450 Object-Oriented Programming (Yahoo free web hosting) Chapter 9 Let us develop

450 Object-Oriented Programming Chapter 9 Let us develop a simple inheritance hierarchy. A typical university community has thousands of people who are community members. These people consist of employees, students and alumni. Employees are either faculty members or staff members. Faculty members are either administrators (such as deans and department chairpersons) or teaching faculty. This yields the inheritance hierarchy shown in Fig. 9.2. Note that the inheritance hierarchy could contain many other classes. For example, students can be graduate students or undergraduate students. Undergraduate students can be freshman, sophomores, juniors, and seniors. And so on. The arrows in the hierarchy represent the is a relationship. For example, based on this class hierarchy that we can state, an Employee is a CommunityMember, or a Teacher is a Faculty member. CommunityMember is the direct superclass of Employee, Student and Alumni. CommunityMember is an indirect superclass of all the other classes in the hierarchy diagram. Note that class Employee is both a subclass of CommunityMember and a superclass of Facultyand Staff. Also, starting from the bottom of the diagram, you can follow the arrows and apply the is a relationship all the way up to the topmost superclass in the hierarchy. For example, an Administratoris a Facultymember, is an Employeeand is a CommunityMember. And, in Java, an Administrator also is an Object because all classes in Java have Object as one of their direct or indirect superclasses. Thus, all classes in Java are related in a hierarchical relationship in which they share the 11 methods defined by class Object, which include the toString and finalize methods discussed previously. Other methods of class Objectare discussed as they are needed in the text. Another substantial inheritance hierarchy is the Shape hierarchy of Figure 9.3. There are abundant examples of hierarchies in the real world, but students are not accustomed to categorizing the real world in this manner, so it takes some adjustment in their thinking. Actually, biology students have had some practice with hierarchies. Everything we study in biology is grouped into a hierarchy headed by living things and these can be plants or animals and so on. To specify that class TwoDimensionalShape is derived from (or inherits from) class Shape, class TwoDimensionalShapecould be defined in Java as follows: CommunityMember Employee Student Faculty Staff Administrator Teacher Alumni Fig. 9.2An inheritance hierarchy for university CommunityMembers. g. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply