Let’s consider several additional examples of polymorphism.
Rectangle is derived from class
Quadrilateral (a four-sided shape), then a
Rectangle is a more specific version of a
Quadrilateral. Any operation (e.g., calculating the perimeter or the area) that can be performed on a
Quadrilateral object can also be performed on a
Rectangle object. These operations also can be performed on other
Quadrilaterals, such as
Trapezoids. The polymorphism occurs when an app invokes a method through a base-class variable—at execution time, the correct derived-class version of the method is called, based on the type of the referenced object. You’ll see a simple ...