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. Top-down design is a problem-solving methodology based on breaking
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/13/2011 for the course CSE 1550 taught by Professor Marianakant during the Fall '10 term at York University.

Ask a homework question - tutors are online