Building an Inheritance Hierarchy

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

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

In the preceding War Games example, the Modem class is the superclass of the ErrorCorrectionModem class. ErrorCorrectionModem is the subclass of Modem. A ...

Get SAMS Teach Yourself Programming with Java™ in 24 Hours, FOURTH 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.