Reverse polymorphism

Now we consider another issue that arises in statically typed object-oriented programming languages. This is the issue of reverse polymorphism.

Polymorphism, as we have noted in previous chapters, means (among other things) that we can assign a value from a child class to a variable that was declared as the parent class. However, having done so, can we go back the other direction?

For example, here I have declared a variable as a Mammal, but assigned it a value of type Dog. But? Can I take a value of type Mammal and assign it to a variable of type Dog?

This problem is known as reverse polymorphism, and it turns out to be surprizingly common.

[audio] [real] Text to accompany slide8, in Chapter 10 of An Introduction to Object-Oriented Programming