{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Dale - Computer Science Illuminated 191

Dale - Computer Science Illuminated 191 - 164 Chapter 6...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
164 Chapter 6 Problem Solving and Algorithm Design Figure 6.7 An example of inheritance Animal Mammal Dog go. Classes lower down in the hierarchy inherit all the behaviors and data of their parent superclass. For example, Maggie, the brown pet, is an instance of the class Labrador. A Labrador is a dog, a dog is a mammal, and a mammal is an animal. Therefore, Maggie inherits all the characteristics of animals, mammals, dogs, and Labradors: She is an affectionate, big brown animal that nursed her puppies. See Figure 6.7. Another example would be a student. A student is a person, so he or she can inherit all the properties of people 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 a service. A student class can call on the services of a library class to check out a book. Note that all classes can collaborate with one another, even those that are related through containment or inheritance.
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}