8.1.3
Superclasses and Subclasses
CLASSES
The class
Point
is a direct subclass of
java.lang.Object
.
The class
java.lang.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 rela
tionship. A class
A
is a subclass of class
C
if either of the following is true:
A
is the direct subclass of
C
.
There exists a class
B
such that
A
is a subclass of
B
, and
B
is a subclass of
C
,
applying this definition recursively.
Class
C
is said to be a
superclass
of class
A
whenever
A
is a subclass of
C
.
In the example:
class Point { int x, y; }
class ColoredPoint extends Point { int color; }
final class Colored3dPoint extends ColoredPoint { int z; }
the relationships are as follows:
The class
Point
is a superclass of class
ColoredPoint
.
The class
Point
is a superclass of class
Colored3dPoint
.
The class
ColoredPoint
is a subclass of class
Point
.
The class
ColoredPoint
is a superclass of class
Colored3dPoint
.
The class
Colored3dPoint
is a subclass of class
ColoredPoint
.
The class
Colored3dPoint
is a subclass of class
Point
.
A compile time error occurs if a class is declared to be a subclass of itself. For
example:
class Point extends ColoredPoint { int x, y; }
class ColoredPoint extends Point { int color; }
causes a compile time error. If circularly declared classes are detected at run time,
as classes are loaded ( 12.2), then a
ClassCircularityError
is thrown.
134
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved