Java Reference
In-Depth Information
one argument of type int , that can satisfy both abstract method specifications, because
the one in interface Colorable requires the same method to return no value, while the
one in class Colored requires the same method to return a value of type int 8.4 ).
A class type should be declared abstract only if the intent is that subclasses can be cre-
ated to complete the implementation. If the intent is simply to prevent instantiation
of a class, the proper way to express this is to declare a constructor (§ 8.8.10 ) of no
arguments, make it private , never invoke it, and declare no other constructors. A class
of this form usually contains class methods and variables.
The class Math is an example of a class that cannot be instantiated; its declaration looks
like this:
Click here to view code image
public final class Math {
private Math() { } // never instantiate this class
. . . declarations of class variables and methods . . .
}
8.1.1.2. final Classes
A class can be declared final if its definition is complete and no subclasses are desired or
required.
It is a compile-time error if the name of a final class appears in the extends clause (§ 8.1.4 ) of
another class declaration; this implies that a final class cannot have any subclasses.
It is a compile-time error if a class is declared both final and abstract , because the implement-
ation of such a class could never be completed (§ 8.1.1.1 ) .
Because a final class never has any subclasses, the methods of a final class are never over-
ridden (§ 8.4.8.1 ).
8.1.1.3. strictfp Classes
The effect of the strictfp modifier is to make all float or double expressions within the class de-
claration (including within variable initializers, instance initializers, static initializers, and
constructors) be explicitly FP-strict (§ 15.4 ).
This implies that all methods declared in the class, and all nested types declared in the class,
are implicitly strictfp .
8.1.2. Generic Classes and Type Parameters
A class is generic if it declares one or more type variables (§ 4.4 ) .
Search WWH ::




Custom Search