Ch. 12 Object-Oriented Programming: Polymorphism
Assume we have a base class Shape and derived classes Triangle and Rectangle. Which of the following member functions should be virtual?
isRegular.
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?
lapWings.
Which attribute or behavior would we not factor out of the Pants and Socks classes and into the Clothing base class?
numberOfPockets.
The ________ operator returns a reference to a ________ object:
typeid, type_info
Polymorphism is implemented via:
virtual functions and dynamic binding.
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:
virtual.
The line: virtual double earnings() const = 0; appears in a class definition. You cannot deduce that:
All classes that directly inherit from this class will override this method.
Run-time type information can be used to determine:
An object's type.
The line: virtual double functionX() const = 0; in a class definition indicates that the class is probably a:
Base class.
virtual functions must:
Be declared virtual in the base class.
Problems using switch logic to deal with many objects of different types do not include:
Not being able to implement separate functions on different objects.
Which of the following is not allowed?
Objects of abstract classes.
dynamic_cast is often used to:
Downcast pointers.
An abstract class will:
Have at least one 0 in its vtable.
The C++ compiler makes objects take up more space in memory if they:
Have virtual functions.
Which statement is not true about dynamic binding?
It eliminates the usefulness of separate header and source files.
Downcasting enables:
Making a base-class pointer into a derived-class pointer.
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; };
There are no pure virtual functions.
Which of the following statements about virtual functions is false?
They do not remain virtual down the inheritance hierarchy.
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();
Yes.
Abstract classes:
Are defined, but the programmer never intends to instantiate any objects from them.
Which of the following assignments would be a compilation error?
Assigning the address of a base-class object to a derived-class pointer.
Polymorphism and virtual functions are not appropriate for:
Programs that have strict memory and processor requirements.
Concrete classes that inherit virtual functions but do not override their implementations:
Receive pointers to their base classes' virtual functions.
The main difference between a pure virtual function and a virtual function is:
That a pure virtual function cannot have an implementation.
Abstract classes do not necessarily have:
Zero references to their class.
virtual destructors must be used when:
delete is used on a base-class pointer to a derived-class object.