Java Reference
In-Depth Information
• It is the only class in Java that does not have a superclass.
• All Java classes inherit the methods of Object .
Because every class (except Object ) has a superclass, classes in Java form a class
hierarchy, which can be represented as a tree with Object at its root.
Object has no superclass, but every other class has exactly one
superclass. A subclass cannot extend more than one super‐
class. See Chapter 4 for more information on how to achieve a
similar result.
m
g
O
Figure 3-1 shows a partial class hierarchy diagram that includes our Circle and
PlaneCircle classes, as well as some of the standard classes from the Java API.
Figure 3-1. A class hierarchy diagram
Subclass Constructors
Look again at the PlaneCircle() constructor from Example 3-3 :
public PlaneCircle ( double r , double x , double y ) {
super ( r ); // Invoke the constructor of the superclass, Circle()
this . cx = x ; // Initialize the instance field cx
this . cy = y ; // Initialize the instance field cy
}
Although this constructor explicitly initializes the cx and cy fields newly defined by
PlaneCircle , it relies on the superclass Circle() constructor to initialize the
 
Search WWH ::




Custom Search