The Car and Truck interfaces are extending (children of) the Vehicle interface. It means that the class that implements the Car interface (let's give such a class the name CarImpl), for example, when instantiated, creates an object that has three types – Vehicle, Car, and CarImpl. These types are similar to passports of a person who is a citizen of three countries. Each citizenship carries specific rights and restrictions, and a person chooses how to present themselves in different situations of international travel, the same way an object of the CarImpl class can be cast to any of these types, provided the type is accessible in the code that does the casting. And here is what we mean by type accessibility: ...
Taking advantage of polymorphism
Get Introduction to Programming 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.