Deck 15: Polymorphism and Virtual Functions
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/22
Play
Full screen (f)
Deck 15: Polymorphism and Virtual Functions
1
In C++, polymorphism is based on the ability to make member functions of a class
A) static.
B) protected.
C) virtual.
D) encapsulated.
E) None of the above
A) static.
B) protected.
C) virtual.
D) encapsulated.
E) None of the above
C
2
________ functions are dynamically bound by the compiler.
A) Constructor
B) Destructor
C) Static
D) Virtual
E) None of the above
A) Constructor
B) Destructor
C) Static
D) Virtual
E) None of the above
D
3
To indicate that a member function of a class is pure virtual,
A) you use the keywords pure virtual.
B) you must put = 0 where the body of the function would go.
C) you must include the header file.
D) All of the above
E) None of the above
A) you use the keywords pure virtual.
B) you must put = 0 where the body of the function would go.
C) you must include the
D) All of the above
E) None of the above
B
4
An abstract class is somewhat restricted in how it can be used because
A) it cannot use dynamic binding for its member functions.
B) it cannot use static binding for its member functions.
C) All of its members must be public.
D) the compiler does not allow objects of the class to be created.
E) None of the above
A) it cannot use dynamic binding for its member functions.
B) it cannot use static binding for its member functions.
C) All of its members must be public.
D) the compiler does not allow objects of the class to be created.
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
5
Static binding occurs when the compiler binds a function call at compile time.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
6
When the compiler binds a call to a member function using only information available at compile time, the compiler is said to use ________ binding.
A) local
B) safe
C) static
D) dynamic
E) None of the above
A) local
B) safe
C) static
D) dynamic
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
7
In C++ polymorphism is very difficult to achieve unless you also use inheritance.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
8
When more than one class is derived from a base class, the situation is called
A) polymorphism.
B) population.
C) multiplicity.
D) encapsulation.
E) None of the above
A) polymorphism.
B) population.
C) multiplicity.
D) encapsulation.
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
9
The term ________ means the ability to take many forms.
A) inheritance
B) polymorphism
C) member function
D) encapsulation
E) None of the above
A) inheritance
B) polymorphism
C) member function
D) encapsulation
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
10
When a virtual member function of a class in a class hierarchy is invoked through a pointer to an object in the class hierarchy, the compiler will select the member function to be invoked
A) from the class of the type of the pointer.
B) from the class of the object that is pointed to.
C) from the base class of the inheritance hierarchy.
D) from the derived class of the base pointer object.
E) None of the above
A) from the class of the type of the pointer.
B) from the class of the object that is pointed to.
C) from the base class of the inheritance hierarchy.
D) from the derived class of the base pointer object.
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
11
Polymorphism in C++ will not work unless ________.
A) pointers or references are being used
B) the members of the class are public
C) the header file is included
D) All of the above
E) None of the above
A) pointers or references are being used
B) the members of the class are public
C) the
D) All of the above
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
12
A virtual member function of class that should not be overridden in a derived class should be declared
A) with the keyword const.
B) with the keyword final.
C) with symbol ! followed by the keyword override.
D) as private in its class.
E) as protected in its class.
A) with the keyword const.
B) with the keyword final.
C) with symbol ! followed by the keyword override.
D) as private in its class.
E) as protected in its class.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
13
An abstract class is
A) one that has at least one pure virtual function.
B) one that supports polymorphism.
C) one that has all of its member functions declared private.
D) one that has all of its member variables declared private.
E) None of the above
A) one that has at least one pure virtual function.
B) one that supports polymorphism.
C) one that has all of its member functions declared private.
D) one that has all of its member variables declared private.
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
14
________ to a base class may be assigned the address of a derived class object.
A) Access specifiers
B) Static members
C) Private members
D) Pointers
E) None of the above
A) Access specifiers
B) Static members
C) Private members
D) Pointers
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
15
Polymorphism is when ________ in a class hierarchy perform differently, depending upon the class of the object making the call.
A) base class constructors
B) derived class destructors
C) member functions
D) derived class constructors
E) None of the above
A) base class constructors
B) derived class destructors
C) member functions
D) derived class constructors
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
16
A virtual function is declared by placing the keyword ________ in front of the return type in the base class's function declaration.
A) virtual
B) private
C) public
D) protected
E) None of the above
A) virtual
B) private
C) public
D) protected
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
17
Declaring a member function of a class to be a ________ will cause the C++ compiler to use dynamic binding.
A) constructor function
B) destructor function
C) static function
D) virtual function
E) None of the above
A) constructor function
B) destructor function
C) static function
D) virtual function
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
18
Pointers to a base class may be assigned the address of a derived class object.
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
19
A class with at least one pure virtual function is called
A) a pure virtual class.
B) a virtual base class.
C) an abstract class.
D) All of the above
E) None of the above
A) a pure virtual class.
B) a virtual base class.
C) an abstract class.
D) All of the above
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
20
A pure virtual function
A) is a virtual function that has been completely debugged.
B) is a virtual function that has no implementation.
C) is a virtual function that performs a single task in program.
D) is one that is only called from within a virtual constructor.
E) None of the above
A) is a virtual function that has been completely debugged.
B) is a virtual function that has no implementation.
C) is a virtual function that performs a single task in program.
D) is one that is only called from within a virtual constructor.
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
21
If you want to make sure that member function of a class overrides another function in a base class, you should declare the function with the keyword
A) override.
B) public.
C) final.
D) private.
E) None of the above
A) override.
B) public.
C) final.
D) private.
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck
22
A pure virtual function
A) must be overridden in a derived class for the function to be useful.
B) executes more efficiently than a non-pure virtual function.
C) must be accompanied by a virtual constructor of the same class.
D) All of the above
E) None of the above
A) must be overridden in a derived class for the function to be useful.
B) executes more efficiently than a non-pure virtual function.
C) must be accompanied by a virtual constructor of the same class.
D) All of the above
E) None of the above
Unlock Deck
Unlock for access to all 22 flashcards in this deck.
Unlock Deck
k this deck