164Chapter 6Problem Solving and Algorithm DesignFigure 6.7An example of inheritanceAnimalMammalDoggo. Classes lower down in the hierarchy inherit all the behaviors and dataof their parent superclass.For example, Maggie, the brown pet, is an instance of the classLabrador. A Labrador is a dog, a dog is a mammal, and a mammal is ananimal. Therefore, Maggie inherits all the characteristics of animals,mammals, dogs, and Labradors: She is an affectionate, big brown animalthat nursed her puppies. See Figure 6.7. Another example would be astudent. A student is a person, so he or she can inherit all the properties ofpeople and add the behavior of going to school.The third way that classes can relate to one another is through collabo-ration. One class can call upon another class to provide information or aservice. A student class can call on the services of a library class to checkout a book. Note that all classes can collaborate with one another, eventhose that are related through containment or inheritance.
This is the end of the preview.
access the rest of the document.