The JavaTM Tutorial
Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Trail: Learning the Java Language
Lesson: Classes and Inheritance

Managing Inheritance

The Object (in the API reference documentation) class, defined in the java.lang package, defines and implements behavior common to all objects. As depicted in the following figure, many classes derive from Object, many classes derive from those classes, and so on, forming a hierarchy of classes.

All Classes are Descendants of Object

All Classes are Descendants of Object

At the top of the hierarchy, Object is the most general of all classes. Classes near the bottom of the hierarchy provide more specialized behavior. A subclass derives from another class. The term superclass refers to a class's direct ancestor or to any of its ascendant classes. Every class has one and only one direct superclass (single inheritance).

A subclass inherits all the member variables and methods from its superclass. However, the subclass might not have access to an inherited member variable or method. For example, a subclass cannot access a private member inherited from its superclass. One might think, then, that the item was not inherited at all. But the item is inherited. This becomes important when using an inner class, which does have access to its enclosing class's private members. Note that constructors are not members and so are not inherited by subclasses.


Previous Page Lesson Contents Next Page Start of Tutorial > Start of Trail > Start of Lesson Search
Feedback Form

Copyright 1995-2005 Sun Microsystems, Inc. All rights reserved.