- 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.
- A tightly encapsulated class allows access to data only through accessor and mutator methods.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- static inner class can only access static variables and methods of enclosing class.
- 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.
- 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.
- A non-static Inner class cannot have static fields or methods , classes
and interfaces ( because nested interfaces are implicitly static).
- 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.
- If outer class i.e. enclosing class is alone instantiated then the constructor of its member classes are not executed.
- ‘this’ and ‘super’ keywords cannot be used in a static method.
- 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.