A class C inherits from its direct superclass type D all concrete methods m (both static and instance) for which all of the following are true:
mis a member of D.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
mas a member of D.
A class C inherits from its direct superclass type and direct superinterface types all abstract and default (§9.4) methods m for which all of the following are true:
mis a member of the direct superclass type or a direct superinterface type of C, known in either case as D.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
mas a member of D. - No concrete method inherited by C from its direct superclass type has a signature that is a subsignature of the signature of
mas a member of D. - There exists no method
m'that is a member of the direct superclass type or a direct superinterface type of C, D' (mdistinct fromm', D distinct from D'), such thatm'overrides from the class or interface of D' the declaration of the methodm(§8.4.8.1, §9.4.1.1).
Inheritance for interfaces is defined in §9.1.3.
A class does not inherit private or static methods from its superinterface types.
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: