Java Reference
In-Depth Information
It is a compile-time error if the
ClassType
names the class
Enum
or any invocation of it.
If the
TypeDeclSpecifier
is followed by any type arguments, it must be a correct invocation
of the type declaration denoted by
TypeDeclSpecifier
, and none of the type arguments may
be wildcard type arguments, or a compile-time error occurs.
Given a (possibly generic) class declaration for
C
<
F
1
,...,
F
n
>
(
n
≥ 0,
C
≠
Object
), the direct
superclass of the class type
C
<
F
1
,...,
F
n
>
is the type given in the
extends
clause of the declar-
ation of
C
if an
extends
clause is present, or
Object
otherwise.
Let
C
<
F
1
,...,
F
n
>
(
n
> 0) be a generic class declaration. The direct superclass of the
parameterized class type
C
<
T
1
,...,
T
n
>
, where
T
i
(1 ≤
i
≤
n
) is a type, is
D
<
U
1
θ,...,
U
k
θ
>
, where
D
<
U
1
,...,
U
k
>
is the direct superclass of
C
<
F
1
,...,
F
n
>
, and θ is the substitution
[
F
1
:=
T
1
,...,
F
n
:=
T
n
]
.
The direct superclass of an enum type
E
is
Enum<
E
>
.
A class is said to be a
direct subclass
of its direct superclass. The direct superclass is the
class from whose implementation the implementation of the current class is derived.
Example 8.1.4-1. Direct Superclasses and Subclasses
class Point { int x, y; }
final class ColoredPoint extends Point { int color; }
class Colored3DPoint extends ColoredPoint { int z; } // error
Here, the relationships are as follows:
• The class
Point
is a direct subclass of
Object
.
• The class
Object
is the direct superclass of the class
Point
.
• The class
ColoredPoint
is a direct subclass of class
Point
.
• The class
Point
is the direct superclass of class
ColoredPoint
.
The declaration of class
Colored3dPoint
causes a compile-time error because it attempts
to extend the final class
ColoredPoint
.
The
subclass
relationship is the transitive closure of the direct subclass relationship. A class
A
is a subclass of class
C
if either of the following is true:
•
A
is the direct subclass of
C