Deck 12: Object-Oriented Programming: Polymorphism
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/27
Play
Full screen (f)
Deck 12: Object-Oriented Programming: Polymorphism
1
Which of the following statements is true?
A) In C++11, all classes can be used as base classes.
B) In C++11, only classes that are not declared as final can be used as base classes.
C) In C++11, only classes that are declared as base can be used as base classes.
D) None of the above
A) In C++11, all classes can be used as base classes.
B) In C++11, only classes that are not declared as final can be used as base classes.
C) In C++11, only classes that are declared as base can be used as base classes.
D) None of the above
B
2
The line: virtual double earnings() const = 0;
Appears in a class definition. You cannot deduce that:
A) All classes that directly inherit from this class will override this method.
B) This class is an abstract class.
C) Any concrete class derived from this class will have an earnings function.
D) This class will probably be used as a base class for other classes.
Appears in a class definition. You cannot deduce that:
A) All classes that directly inherit from this class will override this method.
B) This class is an abstract class.
C) Any concrete class derived from this class will have an earnings function.
D) This class will probably be used as a base class for other classes.
A
3
[C++11] In C++11, you can tell the compiler to explicitly generate the default version of a default constructor, copy constructor, move constructor, copy assignment operator, move assignment operator or destructor by following the special member function's prototype with ________.
A) default
B) explicit
C) (default)
D) = default
A) default
B) explicit
C) (default)
D) = default
D
4
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
A) eat
B) sleep
C) move
D) flapWings
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
5
Virtual functions must:
A) Be overridden in every derived class.
B) Be declared virtual in every derived class.
C) Be declared virtual in the base class.
D) Have the same implementation in every derived class.
A) Be overridden in every derived class.
B) Be declared virtual in every derived class.
C) Be declared virtual in the base class.
D) Have the same implementation in every derived class.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
6
Abstract classes:
A) Contain at most one pure virtual function.
B) Can have objects instantiated from them if the proper permissions are set.
C) Cannot have abstract derived classes.
D) Are defined, but the programmer never intends to instantiate any objects from them.
A) Contain at most one pure virtual function.
B) Can have objects instantiated from them if the proper permissions are set.
C) Cannot have abstract derived classes.
D) Are defined, but the programmer never intends to instantiate any objects from them.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
7
Virtual destructors must be used when:
A) The constructor in the base class is virtual.
B) delete is used on a base-class pointer to a derived-class object.
C) delete is used on a derived-class object.
D) A constructor in either the base class or derived class is virtual.
A) The constructor in the base class is virtual.
B) delete is used on a base-class pointer to a derived-class object.
C) delete is used on a derived-class object.
D) A constructor in either the base class or derived class is virtual.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
8
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.
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
9
Downcasting enables:
A) A derived-class object to be treated as a base-class object.
B) A base-class object to be treated as a derived-class object.
C) Making a base-class pointer into a derived-class pointer.
D) Making a derived-class pointer into a base -class pointer.
A) A derived-class object to be treated as a base-class object.
B) A base-class object to be treated as a derived-class object.
C) Making a base-class pointer into a derived-class pointer.
D) Making a derived-class pointer into a base -class pointer.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
10
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.
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
11
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.
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
12
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;
};
A) There are no pure virtual functions.
B) There is a non-virtual function.
C) private variables are being accessed by a public function.
D) Nothing, it functions fine as an abstract class.
{
Public:
Virtual double print() const;
Double area() const {return base * height;}
Private:
Double base;
Double height;
};
A) There are no pure virtual functions.
B) There is a non-virtual function.
C) private variables are being accessed by a public function.
D) Nothing, it functions fine as an abstract class.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
13
To help prevent errors, apply C++11's ________ keyword to the prototype of every derived-class function that overrides a base-class virtual function.
A) virtual
B) abstract
C) overridable
D) None of the above.
A) virtual
B) abstract
C) overridable
D) None of the above.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
14
An abstract class will:
A) Have all zero function pointers in its vtable.
B) Have at least one zero function pointer in its vtable.
C) Share a vtable with a derived class.
D) Have fewer zero function pointers in its vtable than concrete classes have.
A) Have all zero function pointers in its vtable.
B) Have at least one zero function pointer in its vtable.
C) Share a vtable with a derived class.
D) Have fewer zero function pointers in its vtable than concrete classes have.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
15
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.
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following statements about polymorphism is false?
A) With polymorphism, you can direct a variety of objects to behave in manners appropriate to those objects without even knowing their types.
B) With polymorphism, new types of objects that can respond to existing messages can easily be incorporated into a system without modifying the base system.
C) Polymorphism enables you to deal in specifics and let the execution-time environment concern itself with the generalities.
D) To get polymorphic behavior among existing objects, those objects must be instantiated from classes in the same inheritance hierarchy.
A) With polymorphism, you can direct a variety of objects to behave in manners appropriate to those objects without even knowing their types.
B) With polymorphism, new types of objects that can respond to existing messages can easily be incorporated into a system without modifying the base system.
C) Polymorphism enables you to deal in specifics and let the execution-time environment concern itself with the generalities.
D) To get polymorphic behavior among existing objects, those objects must be instantiated from classes in the same inheritance hierarchy.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
17
Which of the following is not allowed?
A) Objects of abstract classes.
B) Multiple pure virtual functions in a single abstract class.
C) References to abstract classes.
D) Arrays of pointers to abstract classes.
A) Objects of abstract classes.
B) Multiple pure virtual functions in a single abstract class.
C) References to abstract classes.
D) Arrays of pointers to abstract classes.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
18
Polymorphism is implemented via:
A) Member functions.
B) virtual functions and dynamic binding.
C) inline functions.
D) Non-virtual functions.
A) Member functions.
B) virtual functions and dynamic binding.
C) inline functions.
D) Non-virtual functions.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following assignments would be a compilation error?
A) Assigning the address of a base-class object to a base-class pointer.
B) Assigning the address of a base-class object to a derived-class pointer.
C) Assigning the address of a derived-class object to a base-class pointer.
D) Assigning the address of a derived-class object to a derived-class pointer.
A) Assigning the address of a base-class object to a base-class pointer.
B) Assigning the address of a base-class object to a derived-class pointer.
C) Assigning the address of a derived-class object to a base-class pointer.
D) Assigning the address of a derived-class object to a derived-class pointer.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
20
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
A) private
B) virtual
C) protected
D) friend
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
21
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.
A) Are derived from base classes.
B) Have virtual functions.
C) Have only protected members.
D) Are referenced by pointers.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
22
The __________ operator returns a reference to a __________ object:
A) typeid, type_info
B) typeinfo, type_id
C) typeid, data_type
D) typeinfo, type
A) typeid, type_info
B) typeinfo, type_id
C) typeid, data_type
D) typeinfo, type
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
23
Dynamic_cast is often used to:
A) Perform type checking for objects.
B) Convert pointers to strings.
C) Upcast pointers.
D) Downcast pointers.
A) Perform type checking for objects.
B) Convert pointers to strings.
C) Upcast pointers.
D) Downcast pointers.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
24
The line: virtual double functionX() const = 0;
In a class definition indicates that the class is probably a:
A) Base class.
B) Derived class.
C) Protected class.
D) Library class.
In a class definition indicates that the class is probably a:
A) Base class.
B) Derived class.
C) Protected class.
D) Library class.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
25
Abstract classes do not necessarily have:
A) A 0 pointer in their vtable.
B) A virtual function prototype with the notation = 0.
C) Zero instances of their class.
D) Zero references to their class.
A) A 0 pointer in their vtable.
B) A virtual function prototype with the notation = 0.
C) Zero instances of their class.
D) Zero references to their class.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
26
Run-time type information can be used to determine:
A) A function's return type.
B) A function's argument type.
C) An object's type.
D) The number of arguments a function takes.
A) A function's return type.
B) A function's argument type.
C) An object's type.
D) The number of arguments a function takes.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck
27
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.
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.
Unlock Deck
Unlock for access to all 27 flashcards in this deck.
Unlock Deck
k this deck