Deck 13: Object-Oriented Programming: Polymorphism

Full screen (f)
exit full mode
Question
An abstract class will:

A) Have all zeros in its vtable.
B) Have at least one 0 in its vtable.
C) Share a vtable with a derived class.
D) Have fewer 0's in its vtable than concrete classes have.
Use Space or
up arrow
down arrow
to flip the card.
Question
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.
Question
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.
Question
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.
Question
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.
Question
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.
Question
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.
Question
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
Question
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.
Question
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.
Question
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
Question
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.
Question
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.
Question
Polymorphism is implemented via:

A) Member functions.
B) virtual functions and dynamic binding.
C) inline functions.
D) Non-virtual functions.
Question
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.
Question
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.
Question
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.
Question
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.
Question
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.
Question
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.
Question
Dynamic_cast is often used to:

A) Perform type checking for objects.
B) Convert pointers to strings.
C) Upcast pointers.
D) Downcast pointers.
Question
The __________ operator returns a reference to a __________ object:

A) typeid, type_info
B) typeinfo, type_id
C) typeid, data_type
D) typeinfo, type
Question
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.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/23
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 13: Object-Oriented Programming: Polymorphism
1
An abstract class will:

A) Have all zeros in its vtable.
B) Have at least one 0 in its vtable.
C) Share a vtable with a derived class.
D) Have fewer 0's in its vtable than concrete classes have.
B
2
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.
C
3
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.
A
4
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
5
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
6
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
7
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
8
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
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
9
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
10
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
11
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
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
12
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
13
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
14
Polymorphism is implemented via:

A) Member functions.
B) virtual functions and dynamic binding.
C) inline functions.
D) Non-virtual functions.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
15
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
16
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
17
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
18
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
19
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
20
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
21
Dynamic_cast is often used to:

A) Perform type checking for objects.
B) Convert pointers to strings.
C) Upcast pointers.
D) Downcast pointers.
Unlock Deck
Unlock for access to all 23 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
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
23
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.
Unlock Deck
Unlock for access to all 23 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 23 flashcards in this deck.