According section "8.1.1.1" of JLS we have:
A class C has abstract methods if either of the following is true:
• Any of the member methods (§8.2) of C - either declared or inherited - is abstract.
• Any of C's superclasses has an abstract method declared with package access, and there exists no method that overrides the abstract method from C or from a superclass of C
It is interesting, why do we have second option here. In particular, why do we have exactly "package access". And what about "public" or "protected" methods?
From order of most private to most open, the java modifiers go:
Child classes cannot inherit the package methods of a parent class in another package. So a class inheriting from a such a parent would not be abstract according to rule 1. Therefore the 2nd rule exists to address the situation where a child class inherits from an abstract parent and is unable to provide an implementation of the abstract package methods.
It's a nonsensical situation, and I would never expect to see this in any program anywhere. But the language must be fully specified or you could end up with a weird bug that allows a class with undefined methods to be instantiated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With