Polymorphism
Polymorphism is one of the major benefits of inheritance. With polymorphism, the correct function call is decided at run time based on the derived type of a base reference. This is called late binding and is accomplished by casting instances of related types back to a common base class reference. The common base class makes the derived classes related. A graphics program provides a good example. In the graphics program, instead of having separate routines for rectangle, ellipse, and triangle shapes, you write a generic algorithm that uses the base type. This is more extensible and maintainable than handling each type of geometric shape differently. At run time, process a specific instance, such as a rectangle, ellipse, or triangle ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access