Ch02 True/False Indicate whether the statement is true or false. 1. The base class inherits all its properties from the derived class. 2. Inheritance is an is-a relationship. 3. In single inheritance, the derived class is derived from a single base class. 4. A derived class inherits all its data members from the base class; it has none of its own. 5. In multiple inheritance, the derived class is derived from more than one base class. 6. Private members of a base class can be accessed by a derived class. 7. A derived class cannot directly access public members of a base class. 8. The derived class can redefine public member functions of a base class. 9. Overriding a member function is the same as redefining it. 10. Redefining a member function is the same as overloading the member function. 11. A class cannot have a constructor with default parameters. 12. A derived class cannot have a constructor with default parameters. 13. Header files of new classes contain commands that tell the computer where to look for definitions of the base class. 14. A derived class can directly access the protected members of a base class. 15. Composition is a has-a relationship. 16. In C++ the user can create new operators. 17. Default arguments can be used with an overloaded operator. 18. When overloading an operator, the meaning of how an operator works with built-in types remains the same. 19. In C++, every object of a class maintains a hidden pointer to itself, and the name of this pointer is hidden. 20. A friend function is a member function of a class but only has access to the class s public data members. 21. When writing the definition of a friend function, the name of the class and the scope resolution operator do not precede the name of the friend function in the function heading. 22. The function that overloads any of the operators (), [], ->, or = for a class must be declared as a member of the class. 23. For efficiency purposes, wherever possible, you should overload operators as nonmember functions. 24. By using templates, you can write a single code segment for a set of related functions. 25. Just as variables are parameters to functions, data types are parameters to templates. Multiple Choice Identify the choice that best completes the statement or answers the question.
26. Inheritance is an example of a(n) relationship. a. is-a c. friend of b. has-a d. member of 27. The new class that we create from the existing classes is called the. a. base class c. derived class b. modifier class d. extended class 28. In single inheritance, the derived class is derived from base class(es). a. one c. three or more b. two d. virtual 29. If there are three classes, shape, circle, and square, what is the most likely relationship among them? a. The square class is a base class, and shape and circle are derived classes of square. b. The shape class is a base class, and circle and square are derived classes of shape. c. The shape, circle, and square classes are all sibling classes. d. These three classes cannot be related. 30. If class dog has a derived class retriever, which of the following is true? a. In the case of single inheritance, dog can have no other derived classes. b. In the case of single inheritance, retriever is derived from no other class except dog. c. The relationship between these classes implies that dog is a retriever. d. The relationship between these classes implies that retriever has-a dog. 31. To redefine a public member function of a base class in the derived class, the corresponding function in the derived class must have. a. the same name, number, and types of parameters b. only the same name and types of parameters c. only the same name and number d. only the same number and types of parameters 32. We need to ensure that the private member variables that are inherited from the base class are initialized when a of the derived class executes. a. destructor c. copy constructor b. constructor d. friend function 33. The scope resolution operator is. a. : c. :: b. * d. ; 34. When you declare a derived class object, this object inherits the members of the base class, but the derived class object cannot directly access the. a. private data members of the base class b. data members in its own class c. base class constructors d. public data members of the base class 35. A(n) typically serves to initialize the member variables of a derived class. a. inheritor c. deconstructor b. initiator d. constructor 36. A call to the base class constructor is specified in the of a derived class constructor. a. body of the definition c. heading of the definition b. body of the constructor d. heading of the constructor 37. If a class contains the default constructor and no values are specified when the object is declared, the executes and initializes the object. a. default destructor c. last constructor in the program listing
b. first destructor in the program listing d. default constructor 38. To define new classes, you create new files. a. header c. prototype b. friend d. placeholder 39. The definitions of member functions can be placed in a separate file whose extension is. a..cxx c..cpp b..c d..cc 40. To include a system-provided header file, such as iostream, in a user program, you enclose the header file between. a. curly brackets c. asterisks b. angular brackets d. square brackets 41. To include a header file in a program, you use the preprocessor command. a. pragma c. pull b. fetch d. include 42. For a base class to give access to a member to its derived class and still prevent its direct access outside the class, you must declare that member under the member access specifier. a. private c. public b. protected d. shared 43. In, one or more members of a class are objects of another class type. a. inheritance c. composition b. redefinition d. encapsulation 44. Composition is a(n) relationship. a. is a c. was a b. has a d. had a 45. The arguments to the constructor of a member object are specified in the part of the definition of the constructor of the class. a. body c. scope b. pragma d. heading 46. The ability to combine data and operations is called. a. inheritance c. redefinition b. encapsulation d. composition 47. By using templates, you can write a single code segment for a set of related functions, called a. a. function template c. class set b. function type d. class template 48. Like function templates, are used to write a single code segment for a set of related classes. a. function types c. inherited classes b. class templates d. protected members 49. Class templates are called types. a. abstract c. template b. general d. parameterized 50. Passing parameters to a function has an effect at time. a. compile c. run b. link d. build
Ch02 Answer Section TRUE/FALSE 1. ANS: F PTS: 1 REF: 60 2. ANS: T PTS: 1 REF: 60 3. ANS: T PTS: 1 REF: 60-61 4. ANS: F PTS: 1 REF: 60 62 5. ANS: T PTS: 1 REF: 61 6. ANS: F PTS: 1 REF: 62 7. ANS: F PTS: 1 REF: 62 8. ANS: T PTS: 1 REF: 62 9. ANS: T PTS: 1 REF: 63 10. ANS: F PTS: 1 REF: 63 11. ANS: F PTS: 1 REF: 71 12. ANS: F PTS: 1 REF: 71 13. ANS: T PTS: 1 REF: 75 14. ANS: T PTS: 1 REF: 78 15. ANS: T PTS: 1 REF: 79 16. ANS: F PTS: 1 REF: 86 17. ANS: F PTS: 1 REF: 87 18. ANS: T PTS: 1 REF: 87 19. ANS: F PTS: 1 REF: 87 20. ANS: F PTS: 1 REF: 91 21. ANS: T PTS: 1 REF: 91 22. ANS: T PTS: 1 REF: 94 23. ANS: F PTS: 1 REF: 102 24. ANS: T PTS: 1 REF: 108 25. ANS: T PTS: 1 REF: 109 MULTIPLE CHOICE 26. ANS: A PTS: 1 REF: 60 27. ANS: C PTS: 1 REF: 60 28. ANS: A PTS: 1 REF: 60-61 29. ANS: B PTS: 1 REF: 61 30. ANS: B PTS: 1 REF: 61 31. ANS: A PTS: 1 REF: 63 32. ANS: B PTS: 1 REF: 63 33. ANS: C PTS: 1 REF: 67 34. ANS: A PTS: 1 REF: 69 35. ANS: D PTS: 1 REF: 69 36. ANS: C PTS: 1 REF: 70 37. ANS: D PTS: 1 REF: 70 38. ANS: A PTS: 1 REF: 75
39. ANS: C PTS: 1 REF: 76 40. ANS: B PTS: 1 REF: 76 41. ANS: D PTS: 1 REF: 76 42. ANS: B PTS: 1 REF: 78 43. ANS: C PTS: 1 REF: 79 44. ANS: B PTS: 1 REF: 79 45. ANS: D PTS: 1 REF: 83 46. ANS: B PTS: 1 REF: 84 47. ANS: A PTS: 1 REF: 108 48. ANS: B PTS: 1 REF: 111 49. ANS: D PTS: 1 REF: 111 50. ANS: C PTS: 1 REF: 112