Register Now

Login

Lost Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Login

Register Now

Welcome to All Test Answers

Chapter 20 – C How to Program 6e Multiple Choice Test Bank


 

Download  file with the answers

Not a member!
Create a FREE account here to get access and download this file with answers


Chapter 20: Object-Oriented Programming: Inheritance

Section 20.1 Introduction

20.1 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.

20.1 Q2: Which of the following is not a kind of inheritance in C++?
a. public.
b. private.
c. static.
d. protected.

20.1 Q3: The is-a relationship represents.
a. Composition.
b. Inheritance.
c. Information Hiding.
d. A friend.

Section 20.2 Base Classes and Derived Classes

20.2 Q1: Which of the following is most likely a base class of the other three?
a. automobile.
b. convertible.
c. miniVan.
d. sedan.

20.2 Q2: 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.

20.2 Q3: 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 20.3 protected Members

20.3 Q1: 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

20.3 Q2: 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.

Section 20.4 Relationship between Base Classes and Derived Classes

20.4 Q1: Assuming the definition,
class BasePlusCommissionEmployee : public CommissionEmployee
which of the following is false?
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.

20.4 Q2: 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.

20.4 Q3: 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.

20.4 Q4: 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.

Section 20.5 Constructors and Destructors in Derived Classes

20.5 Q1: 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.

20.5 Q2: 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.

20.5 Q3: Suppose class A inherits from base class B. What is the order in which their constructors and destructors will be called when an object of class A is instantiated and then destroyed?
a. B constructor, A constructor, A destructor, B destructor.
b. B constructor, A constructor, B destructor, A destructor.
c. A constructor, B constructor, A destructor, B destructor.
d. A constructor, B constructor, B destructor, A destructor.

Section 20.6 public, protected and private Inheritance

20.6 Q1: 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.

20.6 Q2: 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 20.7 Software Engineering with Inheritance

20.7 Q1: 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.

20.7 Q2: 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.

About

Leave a reply

Captcha Click on image to update the captcha .

error: Content is protected !!