I l@ve RuBoard |
![]() ![]() |
Exercise 5.3A type/subtype inheritance relationship in general reflects an is-a relationship: A range-checking ArrayRC is a kind of Array, a Book is a kind of LibraryRentalMaterial, an AudioBook is a kind of Book, and so on. Which of the following pairs reflects an is-a relationship? (a) member function isA_kindOf function This reflects an is-a relationship. A member function is a specialized instance of a function. Both have a return type, a name, a parameter list, and a definition. In addition, a member function belongs to a particular class, may or may not be a virtual, const, or static member function, and so on. Inheritance correctly models the relationship. (b) member function isA_kindOf class This does not reflect an is-a relationship. A member function has a class that it is a member of, but it is not a specialized instance of a class. Inheritance incorrectly models the relationship. (c) constructor isA_kindOf member function This reflects an is-a relationship. A constructor is a specialized instance of a member function. A constructor must be a member function; however, it has specialized characteristics. Inheritance correctly models the relationship. (d) airplane isA_kindOf vehicle This reflects an is-a relationship. An airplane is a kind of vehicle. A vehicle is an abstract class. Airplane is also an abstract class and subsequently is likely to be inherited from. Inheritance correctly models the relationship. (e) motor isA_kindOf truck This does not reflect an is-a relationship. A motor is part of a truck. A truck has a motor. Inheritance incorrectly models the relationship. (f) circle isA_kindOf geometry This reflects an is-a relationship. A circle is a specialized instance of geometry ?of 2D geometry. Geometry is an abstract base class. Circle is a concrete specialization of geometry. Inheritance correctly models the relationship. (g) square isA_kindOf rectangle This reflects an is-a relationship. Like a circle, a rectangle is a specialized instance of geometry. A square is a further specialization ?a rectangle in which each side is equal. Inheritance correctly models the relationship. (h) automobile isA_kindOf airplane This is neither a has-a nor an is-a relationship. Both an automobile and an airplane are kinds of vehicles. Inheritance incorrectly models the relationship. (i) borrower isA_kindOf library This does not reflect an is-a relationship. A borrower is an object (or component) of a library. A library has one or more borrowers. A borrower is a member of a library but is not a kind of library! Inheritance incorrectly models the relationship. |
I l@ve RuBoard |
![]() ![]() |