Chapter 16

Overriding

We say that a method in a child class overrides a method in the parent class if the two methods have the same name and type signature.1

1. As we will note in a moment, some languages require an additional keyword before overriding will take place. The feature common to all languages, however, is the parent/child relationship and the matching type signatures.

Images

Overriding (also called inclusion polymorphism) is important when it is combined with substitution. Recall that a polymorphic variable can, using the principle of substitution, be declared as one type (for example, the parent type) but in reality hold a value of another ...

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.