Deck 12: Object-Oriented Programming: Inheritance
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/19
Play
Full screen (f)
Deck 12: Object-Oriented Programming: Inheritance
1
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
A) protected, private
B) public, private
C) protected, protected
D) public, protected
C
2
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.
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.
A
3
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.
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.
C
4
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.
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.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
5
The is-a relationship represents.
A) Composition.
B) Inheritance.
C) Information Hiding.
D) A friend.
A) Composition.
B) Inheritance.
C) Information Hiding.
D) A friend.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
6
Which of the following is not a kind of inheritance in C++?
A) public.
B) private.
C) static.
D) protected.
A) public.
B) private.
C) static.
D) protected.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
7
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) 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.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
8
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
A) protected, private, public
B) private, protected, public
C) private, public, protected
D) protected, public, private
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
9
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.
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.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
10
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.
A) Airplanes.
B) Geometric shapes.
C) Animals.
D) Prime numbers.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
11
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.
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 19 flashcards in this deck.
Unlock Deck
k this deck
12
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.
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 19 flashcards in this deck.
Unlock Deck
k this deck
13
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.
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.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
14
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.
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.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
15
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.
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 19 flashcards in this deck.
Unlock Deck
k this deck
16
Which of the following is most likely a base class of the other three?
A) automobile.
B) convertible.
C) miniVan.
D) sedan.
A) automobile.
B) convertible.
C) miniVan.
D) sedan.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
17
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.
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.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
18
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
A) class subclass : private superClass
B) class subclass :: private superClass
C) class subclass < private superClass >
D) class subclass inherits private superClass
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck
19
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.
A) Header files.
B) Source code.
C) Object code.
D) Interface.
Unlock Deck
Unlock for access to all 19 flashcards in this deck.
Unlock Deck
k this deck