Java Reference
In-Depth Information
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.
If a normal class that is not abstract contains an abstract method, then a compile-time error
occurs.
An enum type (§ 8.9 ) must not be declared abstract , or a compile-time error occurs.
It is a compile-time error for an enum type E to have an abstract method m as a member
unless E has one or more enum constants, and all of E 's enum constants have class bodies
that provide concrete implementations of m .
It is a compile-time error for the class body of an enum constant to declare an abstract meth-
od.
A class C has abstract methods if any of the following is true:
C explicitly contains a declaration of an abstract method (§ 8.4.3 ) .
• Any of C 's superclasses has an abstract method and C neither declares nor inherits a
method that implements (§ 8.4.8.1 ) it.
• A direct superinterface (§ 8.1.5 ) of C declares or inherits a method (which is there-
fore necessarily abstract ) and C neither declares nor inherits a method that imple-
ments it.
It is a compile-time error if an attempt is made to create an instance of an abstract class using
a class instance creation expression (§ 15.9 ) .
A subclass of an abstract class that is not itself abstract may be instantiated, resulting in the
execution of a constructor for the abstract class and, therefore, the execution of the field ini-
tializers for instance variables of that class.
It is a compile-time error to declare an abstract class type such that it is not possible to create
a subclass that implements all of its abstract methods. This situation can occur if the class
would have as members two abstract methods that have the same method signature (§ 8.4.2 )
but return types for which there is no type which is return-type-substitutable (§ 8.4.5 ) with
both.
Example 8.1.1.1-1. Abstract Class Declaration
Click here to view code image
abstract class Point {
int x = 1, y = 1;
Search WWH ::




Custom Search