3.5.7 How to Downcast an Object

Downcasting "transforms" or "morphs" an object into a more specialized type. This is done to bring back or add functionality to an object that may have had members stripped away.

Let's say we have an inheritance hierarchy that looks like this:

And we instantiate a MoneyTail type and try and assign its flavor. Because the setter is protected we can't do that from outside the class or any child classes.

But our ChocolateMoneyTail class has a method that assigns the Flavor field in the MonkeyTail class. So how can we do that? We can downcast the MonkeyTail type to its more specific ChocolateMonkeyTail type to get that functionality.