CS 2704 Homework 5: Inheritance Spring 2001 Q A Reason 1 1 A derived type is usually more "specialized" than its base type, and that usually implies the derived type has more operations and/or more attributes than the base type. 2 2 The "has-a" relationship is aggregation. Inheritance reflects an "is-a-kind-of" relationship. 3 2 A derived object has (via inheritance) all the attributes and behaviors of its base type, so the derived type can "mimic" the base type. Obviously that doesn't work in reverse. 4 2 Straight from the notes... if a derived object is assigned to a base object, "slicing" occurs and all the elements added between the derived type and the base type are lost. 5 3 Again, straight from the notes. This could be made legal if the derived type has a suitable copy constructor or assignment operator. 6 3 Protected members are accessible to classes derived from X, and to friends of those classes, but not elsewhere. 7 3 The base class should represent the commonality among the types that are derived directly from it. 8 3 Straight from the notes. 9 1 10 2 By default, the default constructor for the base type is executed before the body of any constructor for the derived type. A non- default base constructor can be selected by using the initializer list in the derived type constructor. 11 3 When a derived object is destroyed, the derived type destructor is executed (to deal with the derived layer), and then the base type destructor is executed (to deal with the base layer). 12 2 It is, however, not legal to declare a derived TYPE unless the base TYPE has been declared (in scope). 13 1 2 would be correct for private inheritance. 3 and 4 make no sense. 14 1 Inheritance represents a generalization/specialization relationship, in which the derived type is a specialized version of the base type. 15 4 Y::Func3(), and by inheritance X::Func1() and X::Func2() 16 3 Y::f, and by inheritance X::m 17 5 Y::Func3() is in the public interface of Y, so it's accessible. X::Func1() is in the public interface of X, and is inherited as a public member of Y, so it's accessible. X::Func2() is inherited by Y, but is inaccessible even to Y. 18 4 This is initializer list syntax. That's used in two ways: to construct aggregated sub-objects and to construct base type layers. In this case, Y is derived from the base X. 19 5 See answer to 18. 20 3 1 and 2 make no sense. An "aisle seat" is a kind of "airplane seat", so 4 makes no sense.