Game Development Reference
In-Depth Information
medium that the object uses to displace itself: land, air, or water. After that, we di-
vide the classes in different subclasses: motorized or not motorized. We could have
chosen to do this the other way round. For some classes, it is not entirely clear where
in the hierarchy they belong: do we say that a motorbike is a special type of bike
(namely one with a motor), or is it a special kind of motorized vehicle (namely one
with only two wheels)?
However, the relationship between the classes themselves should always be clear.
A sailboat is a boat, but a boat is not always a sailboat. A bicycle is a vehicle, but
not every vehicle is a bicycle.
10.7 What You Have Learned
In this chapter, you have learned:
how to use inheritance to structure related classes in a hierarchy;
how to override methods in a subclass to provide specific behavior for that class;
what the difference is between private , protected , and public modifiers;
what the difference is between base and this ;
how to use polymorphism to automatically call the right version of the method.
Search WWH ::




Custom Search