C How To Program Late Objects Version 7th Edition Deitel Test Bank
C How To Program Late Objects Version 7th Edition Deitel Test Bank
13.2 Q1: Which of the following would not be a member function that derived classes Fish, Frog and Bird
should inherit from base class Animal and then provide their own definitions for, so that the function call can be
performed polymorphically?
a. eat
b. sleep
c. move
d. flapWings
ANS d. flapWings
13.3.1 Q1: Employee is a base class and HourlyWorker is a derived class, with a redefined non-virtual
print function. Given the following statements, will the output of the two print function calls be identical?
HourlyWorker h;
Employee *ePtr = &h;
ePtr->print();
ePtr->Employee::print();
a. Yes.
b. Yes, if print is a static function.
c. No.
d. It would depend on the implementation of the print function.
ANS a. Yes.
© Copyright 1992-2010 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
C++ How to Program, 7/e Multiple Choice Test Bank 2 of 4
13.3.4 Q1: If objects of all the classes derived from the same base class all need to draw themselves, the draw()
function would most likely be declared:
a. private
b. virtual
c. protected
d. friend
ANS: b. virtual
13.3.4 Q3: Which of the following statements about virtual functions is false?
a. They allow the program to select the correct implementation at execution time.
b. They can use either static or dynamic binding, depending on the handles on which the functions are called.
c. They do not remain virtual down the inheritance hierarchy.
d. They can be called using the dot operator.
ANS: c. They do not remain virtual down the inheritance hierarchy.
13.4 Q1: Problems using switch logic to deal with many objects of different types do not include:
a. Forgetting to include an object in one of the cases.
b. Having to update the switch statement whenever a new type of object is added.
c. Having to track down every switch statement to do an update of object types.
d. Not being able to implement separate functions on different objects.
ANS: d. Not being able to implement separate functions on different objects.
© Copyright 1992-2010 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
C++ How to Program, 7/e Multiple Choice Test Bank 3 of 4
13.5 Q3: The main difference between a pure virtual function and a virtual function is:
a. The return type.
b. The member access specifier.
c. That a pure virtual function cannot have an implementation.
d. The location in the class.
ANS: c. That a pure virtual function cannot have an implementation.
13.6 Q1: What mistake prevents the following class declaration from functioning properly as an abstract class?
class Shape
{
public:
virtual double print() const;
double area() const { return base * height; }
private:
double base;
double height;
};
Section 13.7 (Optional) Polymorphism, Virtual Functions and Dynamic Binding “Under the Hood”
13.7 Q2: Concrete classes that inherit virtual functions but do not override their implementations:
a. Have vtables which are the same as those of their base classes.
b. Receive their own copies of the virtual functions.
c. Receive pointers to their base classes’ virtual functions.
d. Receive pointers to pure virtual functions.
ANS: c. Receive pointers to their base classes' virtual functions.
13.7 Q3: The C++ compiler makes objects take up more space in memory if they:
a. Are derived from base classes.
b. Have virtual functions.
c. Have only protected members.
d. Are referenced by pointers.
ANS: b. Have virtual functions.
© Copyright 1992-2010 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.
C++ How to Program, 7/e Multiple Choice Test Bank 4 of 4
Section 13.8 Case Study: Payroll System Using Polymorphism and Run-Time Type Information with
downcasting, dynamic_cast, typeid and type_info
© Copyright 1992-2010 by Deitel & Associates, Inc. and Pearson Education, Inc. All Rights Reserved.