Wednesday 21 August 2013

Top Most Overloading, Overriding in Java



  1. When a overloaded method is invoked then the reference type of the variable is considered and the decision as to which method has to be invoked is determined at compile time but if a overridden method is invoked then the run time type of the object is considered and the decision as to which method has to be invoked is determined at runtime.
  2. A tightly encapsulated class allows access to data only through accessor and mutator methods.
  3. If a call to the super class constructor is made with argument i.e for example with the following prototype,
super(ArgList);
    • Here the ArgList can be static variables or static methods belonging to the given class or one of its super class.
    • ArgList cannot refer to instance variables or instance methods belonging to the given class or to one of its super class.

  1. The variables in the superclass can be hidden by variables in the given class.The variable that is accessed is determined at compile time based on the type of reference not based on the run-time type of the object.
  2. A static method in a super class can be overridden by another static method in subclass. If a non-static method overrides a static method or if a static method overrides a non-static method then compile time error sets in.
  3. If a method in a class is private then it cannot be overridden but can be redeclared inside the subclass extending the superclass. This is because the private method of the super class remains invisible to its subclasses.
  4. When an object is being constructed then following two things occur
·         All the initializations of the static variables starting from supermost class(Object class) upto the given class occurs first.
·         This followed by the execution of the constructors starting from the supermost class (Object class)upto the given class occurs.

  1. Just as <EnclosingClassName>.this.<VarName>; can access the variable of the enclosing class from inner class ,<EnclosingClassName>.super.<VarName>
is used to access variable belonging to super class of the enclosing class.
  1. When we have a number of classes forming a inheritance chain then the appropriate overridden method is determined by the run time type of the object
where as if we consider static methods or fields then the appropriate one to be executed will be decide by the reference type.  
  1. If an inner class is non-static then static , non-static , private variables and methods of the enclosing class are accessible to the inner class even in the constructor.
  2. static inner class can only access static variables and methods of enclosing class.
  3. If a static – nested class i.e. top level nested class is instantiated using the form
new <OuterClassName>.<InnerClassName>.();
Then only the constructor of the inner class is executed.
  1. Enclosing class members can access the private variables and methods of its member classes. These private fields and methods can be accessed by other member classes also.
  2. A non-static Inner class cannot have static fields or methods , classes
and interfaces ( because nested interfaces are implicitly static).
  1. The only static fields allowed in a non-static inner class are those marked final and whose value is determined at compile time.
→ here both declaration and initialization must happen in the same statement otherwise compiler error is caused.
  1. If outer class i.e. enclosing class is alone instantiated then the constructor of its member classes are not executed.
  2. ‘this’ and ‘super’ keywords cannot be used in a static method.
  3. We can’t instantiate a non-static inner class from a static method using the form,
new <InnerClassName>();
But through this way a static class can be instantiated in a static method or a
non-static method.

LinkWithin

Related Posts Plugin for WordPress, Blogger...

Labels

Core Java programming core java interview question Core Java Faq's Servlets coding database jsp-servlet spring Java linux unix interview questions java investment bank Web Services Interview investment bank mysql Senior java developer interviews best practices java collection tutorial RMI SQL Eclipse FIX protocol tutorial tibco J2EE groovy java questions SCJP grails java 5 tutorial jdbc beginner error and exception Design Patterns Java Programming Tutorials fundamentals general object oriented programming xml Java Programs Hibernate Examples Flex JAMon Java xml tutorial logging Jsp Struts 2.0 Sybase and SQL Server debugging java interviews performance FIX Protocol interview questions JUnit testing WebSphere date and time tutorial experienced java IO tutorial java concurrency thread Ejb Freshers Papers IT Management Java Exapmle Java Script SQL and database tutorial examples Scwcd ant tutorials concurrency example and tutorial future state homework java changes java threading tricky Agile Business of IT Development JSTL Java JSON tutorial Java multithreading Tutorials PM Scrum data structure and algorithm java puzzles java tips testing tips windows 8 5 way to create Singleton Object Architect Interview Questions and Answers Architecture Architecure Bluetooth server as swing application that searches bluetooth device in 10 meter circle and show all devices. You can send file to any bluetooth device. C Programming CIO Callable Statement in Java Circular dependency of Objects in Java Comparable Example in Collection Custom annotation in Java Developer Interview Divide and rule example in java Drupal Example of Singleton Pattern FIX protocol ForkJoin Example in Java 7 Get data from dynamic table with Java Script Git HTML and JavaScript Health Hello World TCP Client Server Networking Program Hibernate Basics Hibernate Interview Question Answer J2EE Interview Question And Answers J2ME GUI Program JEE Interview QA JMS interview question Java J2EE Hibernate Spring Struts Interview Question Java System Property Java Threads Manager Portlets Provident Fund Read data from any file in same location and give the required result. Reading Properties File in Java Redpoint Rest WebService Client Rest Webservice Test SAL join with ven diagram SCP UNIX COMMAND SSL Singleton Pattern in Java Spring Bean Initialization methods and their order Spring Interview Questions Struts Struts 2.0 Basics Struts 2.0 Design Pattern Submit Html Form With Java Script On The Fly Unix executable For Java Program XOM DOM SAX XP books computers core java; core java; object oriented programming data structure; java investment bank; design pattern dtd duplicate rows in table get browser name with jquery grails podcast inner class java beginners tutorial java cache java networking tutorial java spring java util; java collections; java questions java.java1.5 linked list mailto function with all browser oracle database oracle duplicate rows orm schema social spring mvc questions struts transaction tricks tweet windows xslt