0 оценок0% нашли этот документ полезным (0 голосов)
45 просмотров3 страницы
Private, overridden and hidden members of the super class are not inherited by the subclass. Constructors and initializer blocks are not members of a class and cannot be accessed from outside the package. A static method cannot override inherited instance method, but it can hide a method.
Private, overridden and hidden members of the super class are not inherited by the subclass. Constructors and initializer blocks are not members of a class and cannot be accessed from outside the package. A static method cannot override inherited instance method, but it can hide a method.
Авторское право:
Attribution Non-Commercial (BY-NC)
Доступные форматы
Скачайте в формате DOC, PDF, TXT или читайте онлайн в Scribd
Private, overridden and hidden members of the super class are not inherited by the subclass. Constructors and initializer blocks are not members of a class and cannot be accessed from outside the package. A static method cannot override inherited instance method, but it can hide a method.
Авторское право:
Attribution Non-Commercial (BY-NC)
Доступные форматы
Скачайте в формате DOC, PDF, TXT или читайте онлайн в Scribd
Inheritance of members is closely tied to their declared
accessibility. If a super class member is accessible by its simple name in the subclass, without the use of any extra syntax like super then that member is considered inherited. This means private, overridden and hidden members of the super class are not inherited. Inheritance should not be confused with the existence of such members in the state of subclass object. (Imp!) Private members of the super class are not inherited by the subclass and can only be accessed indirectly. Members that have package accessibility in the super class are also not inherited by subclasses in other packages, as these members are only accessible by their simple names in sub classes within the same package as super class. Since constructors and initializer blocks are not members of a class, they are not inherited by a subclass. Light() is not public is a Light class; cannot be accessed from outside the package. (Protected and Public works). In case, superclass is in a different package with a default constructor having accessibility other than public then superclass cannot be instantiated directly within the subclass, which is in the different package. Superclass (within a different package) constructor can be invoked in a inheritance hierarchy only if it is public or protected. Single or Linear implementation inheritance. Under certain circumstances, a subclass may override a NON-STATIC methods defined in the super class that would otherwise be inherited. The overridden method in the superclass is not inherited by the subclass and the new method in the subclass must uphold the following rules: In case of variable hiding, only name of the variable matters. Access Specifier, Modifiers, DATATYPE doesn’t matter.
For e.g. public int i = 10;
Can be hidden like
protected static int i = 30;
Very Important!!!!!! Subclass cannot override Private methods in superclass as they are not inherited in subclass. If you write the same method in the subclass it will be considered a new method (not overriding) of subclass. Doesn’t matter if you have the same return type or not or same throws clause or not. A static method cannot override inherited instance method, but it can hide a static method if the exact requirements for overriding instance methods are fulfilled. The binding of a method call to a method implementation is done at compile time if the method is static or final ( not very clear) (private methods are implicitly final). Only non-final instance methods in the superclass that are directly accessible from the subclass are eligible for overriding. Overloaded method Resolution depends on the type of object reference not on the type of object, reference is pointing to. Unlike the THIS keyword, the SUPER keyword cannot be used as an ordinary reference. For example it cannot be assigned to other references or cast to other reference types. Constructors cannot be inherited or overridden. They can be overloaded but in the same class. Java requires that any this() class must occur as a first statement in the constructor. This restriction is due to Java’s handling of constructor invocation in the super class when an object of the subclass is created. Super() and this() constructor calls cannot be used simultaneously in the same constructor. Static final variables should be initialized at the time of declaration for e.g. final static int I = 20; Final variables belong to objects must be initialized at the time of declaration or in the constructor. The null reference value can be cast to any reference type. For e.g. Integer I = (Integer) null; No Compile time error-No Runtime Error. Syntax <reference> instanceof <destination type> The instanceof operator returns false if the left hand operand is null. For e.g. boolean flag = null instanceof Object; flag will be false.
Note: V is in relation A is not (In terms of inheritance hierarchy)
If parameters are of mixed type then there
will be an ambiguity, if actual parameters satisfy all the formal parameters