Ch.15 Inheritance, Polymorphism, And Complete Test Bank 9e - Test Bank | C++ Control Structures 9e by Tony Gaddis. DOCX document preview.
Starting Out with C++ from Control Structures to Objects, 9e (Gaddis)
Chapter 15 Inheritance, Polymorphism, and Virtual Functions
TRUE/FALSE
1. In an inheritance situation, you may not pass arguments to a base class constructor.
2. More than one class may be derived from a base class.
3. A derived class may become a base class if another class is derived from it.
4. The base class access specification can be viewed as a filter that base class members must pass through when becoming inherited members of a derived class.
5. When arguments must be passed to the base class constructor, they are passed from the derived class constructor's header line.
6. A member function of a derived class may not have the same name as a member function of a base class.
7. Static binding occurs when the compiler binds a function call with the function call that resides in the same class as the call itself.
8. Pointers to a base class may be assigned the address of a derived class object.
9. A derived class may not have any classes derived from it.
10. In C++11, if a derived class attempts to override a final member function, the compiler generates an error.
11. C++11 provides a way for a derived class to inherit some of the base class's constructors.
12. In C++11, using constructor inheritance, it is possible for any of the base class's constructors to be inherited.
MULTIPLE CHOICE
1. In OOP programming, __________ allows you to create new classes based on existing classes.
a. | polymorphism |
b. | inheritance |
c. | function overloading |
d. | the copy constructor |
e. | None of these |
2. When you derive a class from an existing class, you __________ add new data and functions.
a. | never |
b. | must |
c. | may |
d. | None of these |
3. The __________ members of a base class are never accessible to a derived class.
a. | private |
b. | public |
c. | protected |
d. | All of these |
e. | None of these |
4. The __________ constructor is called before the __________ constructor.
a. | base, derived |
b. | derived, base |
c. | public, private |
d. | private, public |
e. | None of these |
5. A __________ of a base class expects to be overridden in a derived class.
a. | constructor function |
b. | destructor function |
c. | static function |
d. | virtual function |
e. | None of these |
6. The term __________ means the ability to take many forms.
a. | inheritance |
b. | polymorphism |
c. | member function |
d. | encapsulation |
e. | None of these |
7. When the compiler binds a member function call with the version of the function that resides in the same class as the call itself, it is considered
a. | local binding |
b. | safe binding |
c. | static binding |
d. | dynamic binding |
e. | None of these |
8. The compiler performs __________ on virtual functions.
a. | local binding |
b. | additional error checking |
c. | static binding |
d. | dynamic binding |
e. | None of these |
9. When more than one class is derived from a base class, the situation is called
a. | polymorphism |
b. | multiplicity |
c. | population |
d. | encapsulation |
e. | None of these |
10. When a derived class has two or more base classes, the situation is called
a. | multiple inheritance |
b. | multiplicity |
c. | polymorphism |
d. | encapsulation |
e. | None of these |
11. Multiple inheritance opens the opportunity for a derived class to have ___________ members.
a. | dynamic |
b. | private |
c. | public |
d. | ambiguous |
e. | None of these |
12. Which is the base class in the following statement?
class Car : public Vehicle
a. | Car |
b. | Vehicle |
c. | public |
d. | class |
e. | None of these |
13. The following statement allows the __________ members of the Car class to access __________ members of the Vehicle class.
class Car : public Vehicle
a. | private, private |
b. | public, private |
c. | protected, private |
d. | public, protected |
e. | None of these |
14. Which is the derived class in the following statement?
class Car : protected Vehicle
a. | Car |
b. | Vehicle |
c. | protected |
d. | There is no way to tell. |
e. | None of these |
15. What is being protected in the following statement?
class Car : protected Vehicle
a. | derived class functions |
b. | base class members |
c. | derived class data |
d. | future inherited classes |
e. | None of these |
16. Arguments are passed to the base class by the __________ class __________ function.
a. | derived, constructor |
b. | derived, destructor |
c. | base, constructor |
d. | base, destructor |
e. | None of these |
17. Arguments are passed to the base class destructor by the __________ class __________ function.
a. | derived, constructor |
b. | derived, destructor |
c. | base, constructor |
d. | base, destructor |
e. | None of these |
18. Protected members of a base class are like __________, but they may be accessed by derived classes.
a. | constructor functions |
b. | static members |
c. | private members |
d. | public members |
e. | None of these |
19. The __________ destructor is called before the __________ destructor.
a. | base, derived |
b. | derived, base |
c. | public, private |
d. | private, public |
e. | None of these |
20. Which of the following is commonly used to extend a class or to give it additional capabilities?
a. | inheritance |
b. | privacy |
c. | the constructor |
d. | the destructor |
e. | None of these |
21. When member functions behave differently depending on which object performed the call, this is an example of
a. | chaos theory |
b. | virtual insubordination |
c. | polymorphism |
d. | encapsulation |
e. | None of these |
22. A virtual function is a function that expects to be __________ in a derived class.
a. | ignored |
b. | called frequently |
c. | overridden |
d. | private |
e. | None of these |
23. Multiple inheritance is when a __________ class has __________ base classes.
a. | base, no |
b. | derived, two or more |
c. | derived, no |
d. | compound, more than two |
e. | None of these |
24. A virtual function is declared by placing the __________ key word in front of the return type in the base class's function declaration.
a. | virtual |
b. | private |
c. | public |
d. | protected |
e. | None of these |
25. Polymorphism is when __________ in a class hierarchy perform differently, depending on which object performs the call.
a. | base class constructors |
b. | derived class constructors |
c. | member functions |
d. | derived class destructors |
e. | None of these |
26. Functions that are dynamically bound by the compiler are __________ functions.
a. | constructor |
b. | destructor |
c. | static |
d. | virtual |
e. | None of these |
27. C++11 introduced the __________ key word to help prevent subtle errors when overriding virtual functions.
a. | const |
b. | final |
c. | override |
d. | virtual |
e. | None of these |
MULTIPLE RESPONSE
1. Select all that apply. The base class's __________ affects the way its members are inherited by the derived class.
a. | name |
b. | return data type |
c. | access specification |
d. | construction |
e. | None of these |
2. Select all that apply. In an inheritance situation, the new class that you create from an existing class is known as the
a. | derived class |
b. | inheritor |
c. | child class |
d. | parental class |
e. | None of these |
3. Select all that apply. Which of the following constructors cannot be inherited through constructor inheritance?
a. | the default constructor |
b. | the virtual constructor |
c. | the move constructor |
d. | the copy constructor |
e. | the grand constructor |
4. Select all that apply. The base class access specification determines how __________ members in the base class may be accessed by derived classes.
a. | private |
b. | public |
c. | constructed |
d. | protected |
e. | None of these |