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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.