Quiz3-Chapter11 Object-Oriented Programming Inheritance Q
Quiz3-Chapter11 Object-Oriented Programming Inheritance Q
11 12 13 14 15 16 17 18 19
Q4: Which of the following is most likely a base class of the other three?
a. automobile.
b. convertible.
c. miniVan.
d. sedan.
Q5: Which of the following is not a good example of a hierarchy likely to be modeled by inheritance?
a. Airplanes.
b. Geometric shapes.
c. Animals.
d. Prime numbers.
Q6: To declare class subClass a privately derived class of superClass one would write:
a. class subclass : private superClass
b. class subclass :: private superClass
c. class subclass < private superClass >
d. class subclass inherits private superClass
Q8: Assuming the following is the beginning of the constructor definition for class BasePlus-
CommissionEmployee which inherits from class Point,
BasePlusCommissionEmployee::BasePlusCommissionEmployee( string first,
string last, string ssn, double sales, double rate, double salary )
: CommissionEmployee( first, last, ssn, sales, rate )
The second line:
a. Invokes the CommissionEmployee constructor with arguments.
b. Causes a compiler error.
c. Is unnecessary because the CommissionEmployee constructor is called automatically.
d. Indicates inheritance.
Q9: Which of the following is not one of the disadvantages of using the “copy-and-paste” approach to duplicating
code from one class into another class?
a. Errors are prone to be spread around.
b. It is time consuming.
c. It forces the system to store many physical copies of the code, creating a code-maintenance nightmare.
d. All of the above are disadvantages of the “copy-and-paste” approach.
Q12: From most restrictive to least restrictive, the access modifiers are:
a. protected, private, public
b. private, protected, public
c. private, public, protected
d. protected, public, private
Q13: When an object of a derived class is instantiated, the __________ constructor initializes the _________
members.
a. Base class, base class.
b. Derived class, base class.
c. Base class, derived class.
d. Derived class, public.
Q15[C++11]: Which of the following statements about inheriting base class constructors is false?
a. To inherit a base class’s constructors, you write the following line of code in the derived class definition
(BaseClass is the base class’s name):
using BaseClass::BaseClass;
b. If an inherited base-class constructor has default arguments, the line of code in Part (a) causes the compiler
to generate a derived-class constructor with the same default arguments.
c. By default, each inherited constructor has the same access level (public, protected or private) as its
corresponding base-class constructor.
d. If the derived class does not explicitly define constructors, the compiler generates a default constructor in
the derived class—even if it inherits other constructors from its base class.
Q17: When deriving a class from a protected base class, the public members of the base class become _________
and the protected members of the base class become __________?
a. protected, private
b. public, private
c. protected, protected
d. public, protected
Q18: Theoretically, clients do not need to see the _________ of classes from which they derive other classes.
a. Header files.
b. Source code.
c. Object code.
d. Interface.
Q19: Which of the following is true about using inheritance in software engineering?
a. Common attributes and behaviors should be factored out of closely related classes and placed into a base
class from which the original classes can now inherit.
b. It is best to create a huge class library to make it easy for a client to find the most appropriate class for his
or her needs.
c. A class produced through inheritance should be as large as possible to fully encompass all of the
functionality it should offer.
d. The standard C++ libraries that are shipped with C++ compilers are usually enough to accomplish
anything an application might need to do.