Deck 11: Inheritance and Composition
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
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/41
Play
Full screen (f)
Deck 11: Inheritance and Composition
1
Which of the following is true about inheritance?
A) All public member functions of the base class become the public member functions of the derived class.
B) All public member variables of the base class become the public member variables of the derived class.
C) All public members of the base class become the public members of the derived class.
D) The public member variables of the base class become the public or private member variables of the derived class.
A) All public member functions of the base class become the public member functions of the derived class.
B) All public member variables of the base class become the public member variables of the derived class.
C) All public members of the base class become the public members of the derived class.
D) The public member variables of the base class become the public or private member variables of the derived class.
D
2
Consider the following class definition:
The class dClass is derived from the class bClass using the ____ type of inheritance.
A) public
B) private
C) protected
D) static

A) public
B) private
C) protected
D) static
B
3
The constructors of a derived class can (directly) initialize only the (public data) members inherited from the base class of the derived class.
True
4
Existing classes, from which you create new classes, are called ____ classes.
A) child
B) base
C) sibling
D) derived
A) child
B) base
C) sibling
D) derived
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
5
A derived class can directly access the protected members of the base class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
6
The private members of a base class can be directly accessed by a derived class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
7
Classes can create new classes from existing classes.This important feature ____.
A) encourages code reuse
B) aids the separation of data and operations
C) provides public access to the internal state of an object
D) results in more software complexity
A) encourages code reuse
B) aids the separation of data and operations
C) provides public access to the internal state of an object
D) results in more software complexity
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
8
A call to the base class's constructor is specified in the heading of the definition of a derived class constructor.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
9
The class io is the base class of the C++ stream classes istream and ostream.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
10
In protected inheritance, public and protected members of the base class become the protected members of the derived class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
11
A derived class cannot directly access public members of a base class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
12
If the derived class does not override a public member function of the base class, you may specify a call to that public member function by using the name of the function and the appropriate parameter list.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
13
The new classes that we create from existing classes are called ____ classes.
A) sibling
B) base
C) derived
D) parent
A) sibling
B) base
C) derived
D) parent
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following is a valid definition of the derived class bClass? 

Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
15
Inheritance is an example of a(n) ____ relationship.
A) is-a
B) has-a
C) handshaking
D) had-a
A) is-a
B) has-a
C) handshaking
D) had-a
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
16
In multiple inheritance, the derived class has more than one base class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
17
If inheritance is private, all members of the base class, including private members, become private members of the derived class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following class definitions makes the public members of the class aClass become the public members of the class bClass? 

Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
19
____ is a "has-a" relationship.
A) Inheritance
B) Encapsulation
C) Composition
D) Polymorphism
A) Inheritance
B) Encapsulation
C) Composition
D) Polymorphism
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
20
Suppose that bClass is a class.Which of the following statements correctly derives the class dClass from bClass? 

Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
21
To ____ a public member function of a base class in the derived class, the corresponding function in the derived class must have the same name, number, and types of parameters.
A) redefine
B) overload
C) rename
D) reuse
A) redefine
B) overload
C) rename
D) reuse
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
22
The ____ members of an object form its internal state.
A) private
B) protected
C) public
D) static
A) private
B) protected
C) public
D) static
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
23
In OOD, a program is a collection of interacting ____________________; in structured programming, a program is a collection of interacting functions.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
24
____ is the ability to combine data, and operations on that data, in a single unit.
A) Inheritance
B) Encapsulation
C) Polymorphism
D) Composition
A) Inheritance
B) Encapsulation
C) Polymorphism
D) Composition
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
25
Consider the following class definitions:Which of the following statements correctly redefines the member function print of bClass?



Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following statements about inheritance is true if memberAccessSpecifier is protected?
A) The private members of the base class become protected members of the derived class.
B) The derived class can directly access any member of the base class.
C) The public members of the base class become protected members of the derived class.
D) The protected members of the base class become private members of the derived class.
A) The private members of the base class become protected members of the derived class.
B) The derived class can directly access any member of the base class.
C) The public members of the base class become protected members of the derived class.
D) The protected members of the base class become private members of the derived class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
27
The preprocessor directive ____________________ is used to prevent multiple inclusions of a header file in a program.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
28
In ____________________ (aggregation), one or more members of a class are objects of another class type.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
29
What is the output of the following program?



Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
30
The constructor of a derived class cannot directly access the ____________________ member variables of the base class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
31
If the corresponding functions in the base class and the derived class have the same name but different sets of parameters, then this function is ____ in the derived class.
A) reused
B) redefined
C) overloaded
D) overridden
A) reused
B) redefined
C) overloaded
D) overridden
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
32
____ is the ability to use the same expression to denote different operations.
A) Inheritance
B) Encapsulation
C) Polymorphism
D) Composition
A) Inheritance
B) Encapsulation
C) Polymorphism
D) Composition
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
33
Which of the following is true about a derived class?
A) A derived class can directly access any member variable of the base class.
B) A derived class can redefine any public member function of the base class.
C) A derived class can have at most one base class.
D) A derived class can redefine any member function of the base class.
A) A derived class can directly access any member variable of the base class.
B) A derived class can redefine any public member function of the base class.
C) A derived class can have at most one base class.
D) A derived class can redefine any member function of the base class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
34
Consider the following class definitions:Which of the following dClass constructor definitions is valid in C++?



Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
35
The ____ members of an object form its external state.
A) private
B) public
C) protected
D) static
A) private
B) public
C) protected
D) static
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
36
C++ provides ____ functions as a means to implement polymorphism in an inheritance hierarchy, which allows the run-time selection of appropriate member functions.
A) redefined
B) overridden
C) virtual
D) overloaded
A) redefined
B) overridden
C) virtual
D) overloaded
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
37
Consider the following class definitions:Which of the following correctly sets the values of x and y?



Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
38
If the derived class classD overrides a public member function functionName of the base class classB, then to specify a call to that public member function of the base class, you use the statement ____.
A) classD::functionName();
B) classB::functionName();
C) classD.functionName();
D) classB.functionName();
A) classD::functionName();
B) classB::functionName();
C) classD.functionName();
D) classB.functionName();
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
39
OOP implements ____.
A) UML
B) IPE
C) EIP
D) OOD
A) UML
B) IPE
C) EIP
D) OOD
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
40
If inheritance is public, all protected members of the base class are ____________________ members of the derived class.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck
41
C++ provides ____________________ functions as a means to implement polymorphism in an inheritance hierarchy.
Unlock Deck
Unlock for access to all 41 flashcards in this deck.
Unlock Deck
k this deck