-
Bug
-
Resolution: Not an Issue
-
P3
-
None
-
1.1.4, 1.2.0
-
generic
-
generic
allan.jacobs@Eng 1997-10-13
The code that illustrates the problem is in source code files RefAbstract.java
and AccTest08.java. The source codes RefACleaner.java and AccTest15.java
are included to show that all of the problem resides in the definition and
use of the method adeff().
The reason that AccTest08 is not an abstract class is that it has no
abstract methods. From section 8.1.2.1 of JLS, a class has abstract
methods if any of the following is true:
"* It explicitly contains a declaration of an abstract method.
* It inherits an abstract method from its direct superclass.
* A direct superinterface of the class declares or inherits a method
(which is therefore necessarily abstract) and the class neither declares
nor inherits a method that implements it."
In the example below, AccTest15 does not inherit adeff() from RefAbstract
because adeff() has default access and the two classes are in different
packages. It does inherit apubf() and aprotf(), but it has implementations
of these two methods. As all three of the abstract methods of RefAbstract
are accounted for, AccTest15 contains no abstract methods and should be
instantiable.
(This test is relevant for Modena test c0662101).
algol% cat bug08.ksh
#!/bin/ksh
java -fullversion
export CLASSPATH=.
echo "// RefAbstract.java"
cat RefAbstract.java
javac -d . RefAbstract.java
echo "// AccTest08.java"
cat AccTest08.java
javac -d . AccTest08.java
echo "// RefACleaner.java"
cat RefACleaner.java
javac -d . RefACleaner.java
echo "// AccTest15.java"
cat AccTest15.java
javac -d . AccTest15.java
java test.AccTest15
echo 'Execution status='$?
algol% bug08.ksh
java full version "1.1.4n:1997.09.11"
// RefAbstract.java
package ref;
public abstract class RefAbstract {
public void pubf() {}
protected void protf() {}
void deff() {}
private void privf() {}
abstract public void apubf();
abstract protected void aprotf();
abstract void adeff();
}
// AccTest08.java
package test;
public class AccTest08 extends ref.RefAbstract {
public static void main( String[] argv ) {
AccTest08 accTest = new AccTest08();
accTest.pubf();
accTest.protf();
accTest.apubf();
accTest.aprotf();
System.exit(0);
}
public void apubf() {}
protected void aprotf() {}
}
AccTest08.java:4: class test.AccTest08 must be declared abstract. It does not define void adeff() from class ref.RefAbstract.
public class AccTest08 extends ref.RefAbstract {
^
AccTest08.java:6: class test.AccTest08 is an abstract class. It can't be instantiated.
AccTest08 accTest = new AccTest08();
^
2 errors
// RefACleaner.java
package ref;
public abstract class RefACleaner extends RefDefAbstract {
public void pubf() {}
protected void protf() {}
void deff() {}
private void privf() {}
abstract public void apubf();
abstract protected void aprotf();
void adeff() {}
}
abstract class RefDefAbstract {
public void pubf() {}
protected void protf() {}
void deff() {}
private void privf() {}
abstract public void apubf();
abstract protected void aprotf();
abstract void adeff();
}
// AccTest15.java
package test;
public class AccTest15 extends ref.RefACleaner {
public static void main( String[] argv ) {
AccTest15 accTest = new AccTest15();
accTest.pubf();
accTest.protf();
accTest.apubf();
accTest.aprotf();
System.exit(0);
}
public void apubf() {}
protected void aprotf() {}
}
Execution status=0