Polymorphism

In general, polymorphism means the ability to have many forms. Before we look closer at its meaning in computer science, we need to make a couple of important observations that are related to the inheritance hierarchy.

An Object of a Descendant Class Has More Than One Type

Consider our chain of derived classes in Figure 16.9 of Chapter 16. In everyday life, most people agree that a racing car is a car, a car is a surface vehicle, and a surface vehicle is a transportation vehicle. However, the contrary is not true, a car is not necessarily a racing car. In computer science and in C#, this is also the case. An object of type SportsCar is therefore also of type Car and of type SurfaceVehicle and of type TransportationVehicle. Consequently, ...

Get C# Primer Plus 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.