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.
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.