Chapter 10

Subclasses and Subtypes

There is a paradox that lies at the heart of the way inheritance and substitution are used in statically typed object-oriented languages. This paradox derives from the twin concepts of subclass and subtype. In this chapter we will explore these concepts and this paradox.

To say that one class is a subclass of another is to simply assert that it has been built using inheritance. The new class is declared using an existing class as a basis, as in the following Java class declaration.

class Child extends Parent {
    ... // class definition
}

The point is that the subclass relationship is asserting a statement about definition, about how the new class was constructed. It says nothing ...

Get An Introduction to Object-Oriented Programming, 3rd 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.