Deck 11: Object-Oriented Programming: Inheritance

Full screen (f)
exit full mode
Question
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.
Use Space or
up arrow
down arrow
to flip the card.
Question
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.
Question
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.
Question
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
Question
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 line beginning with a colon(:)

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.
Question
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
Question
Which of the following is most likely a base class of the other three?

A) automobile.
B) convertible.
C) miniVan.
D) sedan.
Question
The is-a relationship represents.

A) Composition.
B) Inheritance.
C) Information Hiding.
D) A friend.
Question
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.
Question
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.
Question
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.
Question
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.
Question
Which of the following is not a kind of inheritance in C++?

A) public.
B) private.
C) static.
D) protected.
Question
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
D) class subclass inherits private superClass
Question
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.
Question
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.
Question
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.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/17
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 11: Object-Oriented Programming: Inheritance
1
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.
D
2
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.
A
3
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.
D
4
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
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
5
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 line beginning with a colon(:)

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.
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
6
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
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following is most likely a base class of the other three?

A) automobile.
B) convertible.
C) miniVan.
D) sedan.
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
8
The is-a relationship represents.

A) Composition.
B) Inheritance.
C) Information Hiding.
D) A friend.
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
9
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.
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
10
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.
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
11
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.
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
12
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.
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
13
Which of the following is not a kind of inheritance in C++?

A) public.
B) private.
C) static.
D) protected.
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
14
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
D) class subclass inherits private superClass
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
15
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.
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
16
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.
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
17
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.
Unlock Deck
Unlock for access to all 17 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 17 flashcards in this deck.