© Edward Sciore 2019
Edward ScioreJava Program Designhttps://doi.org/10.1007/978-1-4842-4143-1_3

3. Class Hierarchies

Edward Sciore1 
(1)
Newton, MA, USA
 

Chapter 2 examined how interfaces can extend other interfaces, creating a hierarchy of types. One of the characteristics of an object-oriented language is that classes can extend other classes, creating a class hierarchy. This chapter investigates class hierarchies and the ways they can be used effectively.

Subclasses

Java allows one class to extend another. If class A extends class B, then A is said to be a subclass of B and B is a superclass of A. Subclass A inherits all public variables and methods of its superclass B, as well as all of B’s code for these methods.

The most common example of subclassing ...

Get Java Program Design: Principles, Polymorphism, and Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.