The Java Course provides a general introduction to programming in Java. It is based on A.B. Downey's book, How to Think Like a Computer Scientist. Click here for details.

The Class Hierarchy

In Java, all classes extend some other class. The most basic class is called Object. It contains no instance variables, but it does provide the methods equals and toString, among others.

Many classes extend Object, including almost all of the classes we have written and many of the built-in classes, like Rectangle. Any class that does not explicitly name a parent inherits from Object by default.

Some inheritance chains are longer, though. For example, Slate extends Frame (see Appendix C), which extends Window, which extends Container, which extends Component, which extends Object. No matter how long the chain, Object is the ultimate parent of all classes.

All the classes in Java can be organized into a "family tree" that is called the class hierarchy. Object usually appears at the top, with all the "child" classes below. If you look at the documentation of Frame, for example, you will see the part of the hierarchy that makes up Frame's pedigree.

Last Update: 2011-01-24