Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Inheritance & Polymorphism

In this section, we consider the idea that classes can inherit attributes and behaviour from other classes, adding their own attributes and behaviour as well as altering the behaviour they have inherited.

We look at how to create these ‘subclasses’ in Kotlin. We also look at the impact of overriding inherited methods a subclass. This leads us to an extended example, a graphics application that demonstrates the concepts of dynamic binding and polymorphism.

We conclude the section by examining the idea of multiple inheritance and explaining why Kotlin doesn’t support this feature.