Polymorphism of subclasses
A function inherited by a subclass may behave differently than the function of the superclass.
The subclass is said to override the function of the superclass.
-
Otherwise, subclasses would just augment the data and behavior of superclasses.
-
In this way, two subclasses can behave differently from one another and from their superclass.
-
Code describing shared behavior of subclasses is written only once, in the superclass.
-
Code for subclass is only about things that make that subclass special.
-
Diagram
-
Examples