Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
So far we’ve only been working with a single class, Monster. What if we want to have different kinds of monsters and we want them to behave differently, but we also want them to inherit common functionality?
In other words, suppose we have a werewolf who does everything that a monster does, except that when the growl method gets called on a werewolf, he howls. Additionally, suppose we have a serpent and when the growl method gets called, he hisses. Other than having their own custom growls, both serpents and werewolves should behave just like other monsters.
Perform the following steps so that we can experiment with inheritance:
1. Follow the steps in the New File wizard like you did to create Monster, but create a new empty class called Werewolf. When prompted for what class this one inherits from, enter Monster, as shown in Figure 4.4.