Building an Inheritance Hierarchy

Inheritance, which enables a variety of related classes to be developed without redundant work, makes it possible for code to be passed down from one class to another class to another class. This grouping of classes is called a class hierarchy, and all the standard classes you can use in your Java programs are part of a hierarchy.

Understanding a hierarchy is easier if you understand subclasses and superclasses. A class that inherits from another class is called a subclass. The class that is inherited from is called a superclass.

In the preceding WarGames example, the Modem class is the superclass of the ErrorCorrectionModem class. ErrorCorrectionModem is the subclass of Modem.

A class can have more than one ...

Get Sams Teach Yourself Java™ in 24 Hours, Sixth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.