|
|
|
|
|
|
|
FIGURE 16.1
Hierarchy of animals. |
|
|
|
|
|
|
|
|
Typically, a base class will have more than one derived class. Just as dogs, cats, and horses are all types of mammals, their classes would all derive from the Mammal class. |
|
|
|
|
|
|
|
|
To facilitate the discussion of derivation and inheritance, this chapter focuses on the relationships among a number of classes representing animals. You can imagine that you have been asked to design a children's gamea simulation of a farm. |
|
|
|
|
|
|
|
|
In time, you will develop a whole set of farm animals, including horses, cows, dogs, cats, sheep, and so forth. You will create methods for these classes so that they can act in the ways the child might expect, but for now you'll stub out each method with a simple print statement. |
|
|
|
|
|
|
|
|
New Term: Stubbing out a function means you'll write only enough to show that the function was called, leaving the details for later when you have more time. I've been stubbing out functions for years, just saving up for that glorious day when I have more time. |
|
|
|
|
|