A class C inherits from its direct superclass all concrete methods m (both static and instance) of the superclass for which all of the following are true:
mis a member of the direct superclass of C.mispublic,protected, or declared with package access in the same package as C.- No method declared in C has a signature that is a subsignature (§8.4.2) of the signature of
m.
A class C inherits from its direct superclass and direct superinterfaces all abstract and default (§9.4) methods m for which all of the following are true:
mis a member of the direct superclass or a direct superinterface, D, of C.mispublic,protected, or declared with package access in the same package as C.- No method declared in C has a signature that is a subsignature (§8.4.2) of the signature of
m. - No concrete method inherited by C from its direct superclass has a signature that is a subsignature of the signature of
m. - There exists no method
m' that is a member of the direct superclass or a direct superinterface, D', of C (mdistinct fromm', D distinct from D'), such thatm' overrides from D' (§8.4.8.1, §9.4.1.1) the declaration of the methodm.
A class does not inherit private or static methods from its superinterfaces.
Note that methods are overridden or hidden on a signature-by-signature basis. If, for example, a class declares two public methods with the same name (§8.4.9), and a subclass overrides one of them, the subclass still inherits the other method.
Example 8.4.8-1. Inheritance
interface I1 {
int foo();
}
interface I2 {
int foo();
}
abstract class Test implements I1, I2 {}
Here, the abstract class Test inherits the abstract method foo from interface I1 and also the abstract method foo from interface I2. The key question in determining the inheritance of foo from I1 is: does the method foo in I2 override "from I2" (§9.4.1.1) the method foo in I1? No, because I1 and I2 are not subinterfaces of each other. Thus, from the viewpoint of class Test, the inheritance of foo from I1 is unfettered; similarly for the inheritance of foo from I2. Per §8.4.8.4, class Test can inherit both foo methods; obviously it must be declared abstract, or else override both abstract foo methods with a concrete method.
Note that it is possible for an inherited concrete method to prevent the inheritance of an abstract or default method. (The concrete method will override the abstract or default method "from C", per §8.4.8.1 and §9.4.1.1.) Also, it is possible for one supertype method to prevent the inheritance of another supertype method if the former "already" overrides the latter - this is the same as the rule for interfaces (§9.4.1), and prevents conflicts in which multiple default methods are inherited and one implementation is clearly meant to supersede the other.
Sections: