0% found this document useful (0 votes)
5 views

Quiz3-Chapter11 Object-Oriented Programming Inheritance Q

Chapter 11 focuses on Object-Oriented Programming and inheritance, covering key concepts such as base and derived classes, types of inheritance, and the relationship between them. It includes a series of questions to test understanding of these concepts, including the is-a relationship, access modifiers, and the implications of using inheritance in software engineering. The chapter emphasizes the importance of structuring classes effectively to promote code reuse and maintainability.

Uploaded by

AAA.Bakbergen
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Quiz3-Chapter11 Object-Oriented Programming Inheritance Q

Chapter 11 focuses on Object-Oriented Programming and inheritance, covering key concepts such as base and derived classes, types of inheritance, and the relationship between them. It includes a series of questions to test understanding of these concepts, including the is-a relationship, access modifiers, and the implications of using inheritance in software engineering. The chapter emphasizes the importance of structuring classes effectively to promote code reuse and maintainability.

Uploaded by

AAA.Bakbergen
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

1 of 3

Chapter 11: Object-Oriented Programming: Inheritance


Please answer the questions in the following table.
1 2 3 4 5 6 7 8 9 10

11 12 13 14 15 16 17 18 19

Section 11.1 Introduction

Q1: Select the false statement regarding inheritance.


a. A derived class can contain more attributes and behaviors than its base class.
b. A derived class can be the base class for other derived classes.
c. Some derived classes can have multiple base classes.
d. Base classes are usually more specific than derived classes.

Q2: Which of the following is not a kind of inheritance in C++?


a. public.
b. private.
c. static.
d. protected.

Q3: The is-a relationship represents.


a. Composition.
b. Inheritance.
c. Information Hiding.
d. A friend.

Section 11.2 Base Classes and Derived Classes

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

Section 11.3 Relationship between Base Classes and Derived Classes

Q7: Assuming the definition,


class BasePlusCommissionEmployee : public CommissionEmployee
which of the following is false?
2 of 3

a. The colon ( : ) in the header of the class definition indicates inheritance.


b. The keyword public indicates the type of inheritance.
c. All the public and protected members of class BasePlusCommissionEmployee are inherited as public
and protected members, respectively, into class CommissionEmployee.
d. CommissionEmployee is the base class and BasePlusCommissionEmployee is the derived class.

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.

Q10: protected base class members cannot be accessed by:


a. Functions that are neither friends of the base class, derived-class member functions nor friends of a
derived class.
b. friends of the base class.
c. Functions that are not derived-class member functions.
d. friends of derived classes.

Q11: When should base class members be declared protected?


a. When all clients should be able to access these members.
b. When these members are used only by member functions of this base class.
c. When these members should be available only to derived classes (and friends), but not to other clients.
d. The protected access specified should never be used.

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

Section 11.4 Constructors and Destructors in Derived Classes

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.

Q14: Base class constructors and assignment operators:


a. Are not inherited by derived classes.
b. Should not be called by derived class constructors and assignment operators.
c. Can be inherited by derived classes, but generally are not.
d. Can call derived-class constructors and assignment operators.
3 of 3

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.

Section 11.5 public, protected and private Inheritance

Q16: Which forms of inheritance are is-a relationships?


a. All forms of inheritance are is-a relationships.
b. Only public and private.
c. Only public and protected.
d. Only public.

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

Section 11.6 Software Engineering with Inheritance

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.

You might also like