Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Polymorphism isn’t the same as casting. When you cast a type to another, it behaves like the new type. The code that’s executed is that of the type to which it is cast, not the original type.
Let’s look at an example. Here’s a simple class hierarchy with two classes, each exposing a single member, a property called Name. The Parent class returns the String “Parent” in the get accessor, while the Child class returns the String “Child”. (We’ll examine re-defining inherited members in detail in the next section.)