Exploring polymorphism
Polymorphism has its origins in the Greek terms poly (many) morphe (forms). Any object that passes more than one “is-a” test can be considered polymorphic. Therefore, only objects of the Object
type are not polymorphic as any type passes the “is-a” test for both Object
and itself.
In this section, we will discuss why separating the reference type from the object type is so important. In addition, we will examine method overriding and its critical role in enabling polymorphism.
Separating the reference type from the object type
Now that we have inheritance hierarchies, we will regularly differentiate the reference type from the object type. The reference type can be a class, record, enum or interface. In other words, we have flexibility with regard to the reference type. The object type is more restrictive: the object type is based on non-abstract classes, records, and enums only. In other words, we cannot create objects based...