Name: laC46010 Date: 12/21/99
The JLS, p. 8.4.3.1 requires to report compile-time error for the
following example:
----------------------clss02802_b.java----------------------
package clss02802_b;
abstract class clss02802_a { abstract void m(); }
public class clss02802_b extends clss02802_a { void m(){} }
----------------------clss02802.java------------------------
package clss02802;
import clss02802_b.clss02802_b;
class clss02802_c extends clss02802_b {}
------------------------------------------------------------
However javac (all versions) compiles this program without complaints.
I believe it's indeed a valid Java program and p. 8.4.3.1 doesn't take
into account the case when abstract method in not inherited by
subclass.
p. 8.4.3.1 (p.158 of JLS 1st edition) reads :
"Every subclass of A that is not abstract must provide an
implementation for m, or a compile-time error occurs. More
precisely, for every subclass C of the abstract class A,
if C is not abstract, then there must be some class B such
that all of the following are true:
1) B is a superclass of C or is C itself.
2) B is a subclass of A.
3) B provides a declaration of the method m that is not
abstract, and this declaration is inherited by C,
thereby providing an implementation of method m that
is visible to C.
If there is no such class B, then a compile-time error
occurs."
At the same time JLS, p. 8.2 reads :
"Only members of a class that are declared protected or
public are inherited by subclasses declared in a package
other than the one in which the class is declared."
But in present test, the class "clss02802_c" does not inherit the
method "m" because this method belongs to a class from an another
package and has default access. So the class "clss02802_c" is a
subclass of the abstract class "clss02802_a" and there is no some class
B that "B provides a declaration of the method m that is not abstract,
and this declaration is inherited by C". Therefore compile-time error
^^^^^^^^^^^^
must occur. However javac (all versions) compiles this program without
complaints.
Note that above assertion is reduced in the draft of
the JLS 2nd edition to a single sentence:
"Every subclass of A that is not abstract must provide an
implementation for m, or compile-time error occur."
but it still doesn't explain the discussed case.
======================================================================