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 ...

Get Programming Microsoft® Visual C#® 2008: The Language 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.