532 Object-Oriented (Web hosting plans) Programming Chapter 9 9.4 Define each

532 Object-Oriented Programming Chapter 9 9.4 Define each of the following terms: single inheritance, multiple inheritance, interface, superclass and subclass. 9.5 Discuss why casting a superclass reference to a subclass reference is potentially dangerous. 9.6 Distinguish between single inheritance and multiple inheritance. What feature of Java helps realize the benefits of multiple inheritance? 9.7 (True/False) A subclass is generally smaller than its superclass. 9.8 (True/False) A subclass object is also an object of that subclass s superclass. 9.9 Some programmers prefer not to use protected access because it breaks information hiding in the superclass. Discuss the relative merits of using protected access vs. private access in superclasses. 9.10 Many programs written with inheritance could be solved with composition instead, and vice versa. Discuss the relative merits of these approaches in the context of the Point, Circle, Cylinderclass hierarchy in this chapter. Rewrite the program of Fig. 9.22 Fig. 9.26 (and the supporting classes) to use composition rather than inheritance. After you do this, reassess the relative merits of the two approaches both for the Point, Circle, Cylinder problem and for object-oriented programs in general. 9.11 Rewrite the Point, Circle, Cylinder program of Fig. 9.22 Fig. 9.26 as a Point, Square, Cube program. Do this two ways once with inheritance and once with composition. 9.12 In the chapter, we stated, When a superclass method is inappropriate for a subclass, that method can be overridden in the subclass with an appropriate implementation. If this is done, does the subclass-is-a-superclass-object relationship still hold? Explain your answer. 9.13 Study the inheritance hierarchy of Fig. 9.2. For each class, indicate some common attributes and behaviors consistent with the hierarchy. Add some other classes (e.g., UndergraduateStudent, GraduateStudent, Freshman, Sophomore, Junior, Senior), to enrich the hierarchy. 9.14 Write an inheritance hierarchy for classes Quadrilateral, Trapezoid, Parallelogram, Rectangle and Square. Use Quadrilateral as the superclass of the hierarchy. Make the hierarchy as deep (i.e., as many levels) as possible. The private data of Quadrilateral should include the (x, y) coordinate pairs for the four endpoints of the Quadrilateral. Write a driver program that instantiates and displays objects of each of these classes. [In Chapter 11, Graphics and Java2D, you will learn how to use Java s drawing capabilities.] 9.15 Write down all the shapes you can think of both two-dimensional and three-dimensional and form those shapes into a shape hierarchy. Your hierarchy should have superclass Shape, from which class TwoDimensionalShape and class ThreeDimensionalShape are derived. Once you have developed the hierarchy, define each of the classes in the hierarchy. We will use this hierarchy in the exercises to process all shapes as objects of superclass Shape. 9.16 How is it that polymorphism enables you to program in the general rather than in the specific ? Discuss the key advantages of programming in the general. 9.17 Discuss the problems of programming with switch logic. Explain why polymorphism is an effective alternative to using switchlogic. 9.18 Distinguish between inheriting interface and inheriting implementation. How do inheritance hierarchies designed for inheriting interface differ from those designed for inheriting implementation? 9.19 Distinguish between nonabstract methods and abstract methods. 9.20 (True/False) All methods in an abstract superclass must be declared abstract. 9.21 Suggest one or more levels of abstract superclasses for the Shape hierarchy discussed in the beginning of this chapter (the first level is Shape and the second level consists of the classes TwoDimensionalShape and ThreeDimensionalShape). Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/7/01

Leave a Reply