Search code examples
javaclassmethodsabstractjava-5

Abstract class in Java 5 or previous


I've read in a book ( Programmez en Java 5 et 6 by Claude Delannoy, in French) that in Java 5 and its previous versions, if you have an abstract method in a class then this class is abstract and it's not necessary to mention the keyword abstract before the class.

Is this statement true? I tried to find the Java SE 5 specification but it's unreachable.


Solution

  • Oracle publishes the JLS going back to Java 6: https://docs.oracle.com/javase/specs/ I'm not sure that JLS for Java 5 is available online.

    That said, you're question has the same answer regardless of which Java version is considered:

    Normal classes may have abstract methods (§8.4.3.1, §9.4), that is, methods that are declared but not yet implemented, only if they are abstract classes.

    This means: a class that has an abstract method must be declared abstract otherwise you'll get a compilation error.