October 2019
Intermediate to advanced
434 pages
11h 54m
English
Polymorphism is a concept referring to a class's ability to override behavior inherited from a base class. This allows class hierarchies to define similar patterns or behaviors that can be explicitly defined in child classes. The following is globally one way to think of it: animals move, but not all animals move the same way. We define how a dog moves in one way, but we use an entirely different way to define how a bird moves.
Again building on our previous example, the Programmer class can override the behavior of getFormattedName, which demonstrates the notion of polymorphic behavior, shown as follows:
class Programmer(firstName: String, lastName: String, val favoriteLanguage: String) : Person(firstName, lastName) { override ...
Read now
Unlock full access