Deck 11: Inheritance and Composition

Full screen (f)
exit full mode
Question
The class io is the base class of the C++ stream classes istream and ostream.
Use Space or
up arrow
down arrow
to flip the card.
Question
If inheritance is private, all members of the base class, including private members, become private members of the derived class.
Question
____ is a "has-a" relationship.

A) Inheritance
B) Encapsulation
C) Composition
D) Polymorphism
Question
Existing classes, from which you create new classes, are called ____ classes.

A) child
B) base
C) sibling
D) derived
Question
Suppose that bClass is a class. Which of the following statements correctly derives the class dClass from bClass?

A) class dClass:: public bClass
{
//classMembersList
};
B) class dClass: private bClass
{
//classMembersList
};
C) class dClass:: protected bClass
{
//classMembersList
};
D) class bClass: public dClass
{
//classMembersList
};
Question
The new classes that we create from existing classes are called ____ classes.

A) sibling
B) base
C) derived
D) parent
Question
A derived class can directly access the protected members of the base class.
Question
In protected inheritance, public and protected members of the base class become the protected members of the derived class.
Question
The constructors of a derived class can (directly) initialize only the (public data) members inherited from the base class of the derived class.
Question
The private members of a base class can be directly accessed by a derived class.
Question
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
Question
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.
Question
Consider the following class definition: class dClass: bClass
{
//class members list
};
The class dClass is derived from the class bClass using the ____ type of inheritance.

A) public
B) private
C) protected
D) static
Question
In multiple inheritance, the derived class has more than one base class.
Question
A call to the base class's constructor is specified in the heading of the definition of a derived class constructor.
Question
A derived class cannot directly access public members of a base class.
Question
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.
Question
Inheritance is an example of a(n) ____ relationship.

A) is-a
B) has-a
C) handshaking
D) had-a
Question
Which of the following is a valid definition of the derived class bClass?

A) class aClass: public bClass
{
//)..
};
B) class bClass: public aClass
{
//)..
};
C) class aClass::bClass
{
//)..
};
D) class bClass::aClass
{
//)..
}
Question
Which of the following class definitions makes the public members of the class aClass become the public members of the class bClass?

A) class aClass: public bClass
{
//)..
};
B) class bClass: public aClass
{
//)..
};
C) class bClass: aClass
{
//)..
};
D) class aClass: bClass
{
//)..
};
Question
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.
Question
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
Question
____ is the ability to use the same expression to denote different operations.

A) Inheritance
B) Encapsulation
C) Polymorphism
D) Composition
Question
If inheritance is public, all protected members of the base class are ____________________ members of the derived class.
Question
The ____ members of an object form its external state.

A) private
B) public
C) protected
D) static
Question
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
Question
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.
Question
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();
Question
The preprocessor directive ____________________ is used to prevent multiple inclusions of a header file in a program.
Question
____ is the ability to combine data, and operations on that data, in a single unit.

A) Inheritance
B) Encapsulation
C) Polymorphism
D) Composition
Question
Consider the following class definitions: class bClass
{
Public:
Void set(double a, double b);
//Postcondition: x = a; y = b;
Void print() const;
BClass();
//Postcondition: x = 0; y = 0;
BClass(double a, double b);
//Postcondition: x = a; y = b;
Private:
Double x;
Double y;
};
Class dClass: public bClass
{
Public:
Void set(double a, double b, double c);
//Postcondition: x = a; y = b; z = c;
Void print() const;
DClass();
//Postcondition: x = 0; y = 0; z = 0 ;
DClass(double a, double b, double c);
//Postcondition: x = a; y = b; z = c;
Private:
Double z;
};
Which of the following dClass constructor definitions is valid in C++?

A) dClass::dClass(double a, double b, double c)
: bClass()
{
X = a;
Y = b;
Z = c;
}
B) dClass::dClass(double a, double c)
{
X = a;
Z = c;
}
C) dClass::dClass(double a, double b)
: bClass()
{
X = a;
Y = b;
}
D) dClass::dClass(double a, double b, double c)
: bClass(a, b)
{
Z = c;
}
Question
OOP implements ____.

A) UML
B) IPE
C) EIP
D) OOD
Question
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
Question
What is the output of the following program? #include
Using namespace std;
Class bClass
{
Public:
Void print() const;
BClass(int a = 0, int b = 0);
//Postcondition: x = a; y = b;
Private:
Int x;
Int y;
};
Class dClass: public bClass
{
Public:
Void print() const;
DClass(int a = 0, int b = 0, int c = 0);
//Postcondition: x = a; y = b; z = c;
Private:
Int z;
};
Int main()
{
BClass bObject(2, 3);
DClass dObject(3, 5, 8);
BObject.print();
Cout << endl;
DObject.print();
Cout << endl;
Return 0 ;
}
Void bClass::print() const
{
Cout << x << " " << y << endl;
}
BClass::bClass(int a, int b)
{
X = a;
Y = b;
}
Void dClass::print() const
{
BClass:print();
Cout << " " << z << endl;
}
DClass::dClass(int a, int b, int c)
: bClass(a, b)
{
Z = c;
}

A) 2 3
2 3
B) 2 3
3 5 8
C) 3 5 8
3 5 8
D) 5 8
3 5 8
Question
The ____ members of an object form its internal state.

A) private
B) protected
C) public
D) static
Question
In ____________________, the derived class is derived from a single base class.
Question
Consider the following class definitions: class bClass
{
Public:
Void setX(int a);
//Postcondition: x = a;
Void print() const;
Private:
Int x;
};
Class dClass: public bClass
{
Public:
Void setXY(int a, int b);
//Postcondition: x = a; y = b;
Void print() const;
Private:
Int y;
};
Which of the following correctly sets the values of x and y?

A) void dClass::setXY(int a, int b)
{
BClass::setX(a);
Y = b;
}
B) void dClass::setXY(int a, int b)
{
X = a;
Y = b;
}
C) void dClass::setXY(int a, int b)
{
X = bClass::setX(a);
Y = bClass::setY(b);
}
D) void dClass::setXY(int a, int b)
{
X = bClass.setX(a);
B = y;
}
Question
To define new classes in C++, you create new ____________________ files.
Question
The constructor of a derived class cannot directly access the ____________________ member variables of the base class.
Question
Consider the following class definitions: class bClass
{
Public:
Void setX(int);
Void print() const;
Private:
Int x;
};
Class dClass: public bClass
{
Public:
Void setXY(int, int);
Void print() const;
Private:
Int y;
};
Which of the following statements correctly redefines the member function print of bClass?

A) void dClass::print() const
{
DClass:print();
Cout << " " << y << endl;
}
B) void dClass::print() const
{
Cout << x << " " << y << endl;
}
C) void bClass::print() const
{
Cout << x << " " << y << endl;
}
D) void dClass::print() const
{
BClass::print();
Cout << "y = " << y << endl;
}
Question
The term ____________________ is used to describe the ability to create new objects from existing objects.
Question
In the case of composition, the ____________________ name is used to invoke the constructor.
Question
In object-oriented design, we debug ____________________; in structured programming, we debug functions.
Question
In ____________________ (aggregation), one or more members of a class are objects of another class type.
Question
C++ provides ____________________ functions as a means to implement polymorphism in an inheritance hierarchy.
Question
In ____________________ polymorphism, the (data) type is left unspecified and then later instantiated.
Question
Objects are created when ____________________ variables are declared.
Question
The OOP terminology is influenced by the vocabulary of ____________________, the OOP language largely developed at a Xerox research center during the 1970s.
Question
In OOD, a program is a collection of interacting ____________________; in structured programming, a program is a collection of interacting functions.
Question
In C++, we implement ADT through the use of ____________________.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 11: Inheritance and Composition
1
The class io is the base class of the C++ stream classes istream and ostream.
False
2
If inheritance is private, all members of the base class, including private members, become private members of the derived class.
False
3
____ is a "has-a" relationship.

A) Inheritance
B) Encapsulation
C) Composition
D) Polymorphism
C
4
Existing classes, from which you create new classes, are called ____ classes.

A) child
B) base
C) sibling
D) derived
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
Suppose that bClass is a class. Which of the following statements correctly derives the class dClass from bClass?

A) class dClass:: public bClass
{
//classMembersList
};
B) class dClass: private bClass
{
//classMembersList
};
C) class dClass:: protected bClass
{
//classMembersList
};
D) class bClass: public dClass
{
//classMembersList
};
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
The new classes that we create from existing classes are called ____ classes.

A) sibling
B) base
C) derived
D) parent
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
A derived class can directly access the protected members of the base class.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
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 50 flashcards in this deck.
Unlock Deck
k this deck
9
The constructors of a derived class can (directly) initialize only the (public data) members inherited from the base class of the derived class.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
The private members of a base class can be directly accessed by a derived class.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
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
Unlock Deck
Unlock for access to all 50 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 50 flashcards in this deck.
Unlock Deck
k this deck
13
Consider the following class definition: class dClass: bClass
{
//class members list
};
The class dClass is derived from the class bClass using the ____ type of inheritance.

A) public
B) private
C) protected
D) static
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
In multiple inheritance, the derived class has more than one base class.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
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 50 flashcards in this deck.
Unlock Deck
k this deck
16
A derived class cannot directly access public members of a base class.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
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.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
Inheritance is an example of a(n) ____ relationship.

A) is-a
B) has-a
C) handshaking
D) had-a
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
Which of the following is a valid definition of the derived class bClass?

A) class aClass: public bClass
{
//)..
};
B) class bClass: public aClass
{
//)..
};
C) class aClass::bClass
{
//)..
};
D) class bClass::aClass
{
//)..
}
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following class definitions makes the public members of the class aClass become the public members of the class bClass?

A) class aClass: public bClass
{
//)..
};
B) class bClass: public aClass
{
//)..
};
C) class bClass: aClass
{
//)..
};
D) class aClass: bClass
{
//)..
};
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
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.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
____ is the ability to use the same expression to denote different operations.

A) Inheritance
B) Encapsulation
C) Polymorphism
D) Composition
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
If inheritance is public, all protected members of the base class are ____________________ members of the derived class.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
The ____ members of an object form its external state.

A) private
B) public
C) protected
D) static
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
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.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
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();
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
The preprocessor directive ____________________ is used to prevent multiple inclusions of a header file in a program.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
____ is the ability to combine data, and operations on that data, in a single unit.

A) Inheritance
B) Encapsulation
C) Polymorphism
D) Composition
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
Consider the following class definitions: class bClass
{
Public:
Void set(double a, double b);
//Postcondition: x = a; y = b;
Void print() const;
BClass();
//Postcondition: x = 0; y = 0;
BClass(double a, double b);
//Postcondition: x = a; y = b;
Private:
Double x;
Double y;
};
Class dClass: public bClass
{
Public:
Void set(double a, double b, double c);
//Postcondition: x = a; y = b; z = c;
Void print() const;
DClass();
//Postcondition: x = 0; y = 0; z = 0 ;
DClass(double a, double b, double c);
//Postcondition: x = a; y = b; z = c;
Private:
Double z;
};
Which of the following dClass constructor definitions is valid in C++?

A) dClass::dClass(double a, double b, double c)
: bClass()
{
X = a;
Y = b;
Z = c;
}
B) dClass::dClass(double a, double c)
{
X = a;
Z = c;
}
C) dClass::dClass(double a, double b)
: bClass()
{
X = a;
Y = b;
}
D) dClass::dClass(double a, double b, double c)
: bClass(a, b)
{
Z = c;
}
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
OOP implements ____.

A) UML
B) IPE
C) EIP
D) OOD
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
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
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
What is the output of the following program? #include
Using namespace std;
Class bClass
{
Public:
Void print() const;
BClass(int a = 0, int b = 0);
//Postcondition: x = a; y = b;
Private:
Int x;
Int y;
};
Class dClass: public bClass
{
Public:
Void print() const;
DClass(int a = 0, int b = 0, int c = 0);
//Postcondition: x = a; y = b; z = c;
Private:
Int z;
};
Int main()
{
BClass bObject(2, 3);
DClass dObject(3, 5, 8);
BObject.print();
Cout << endl;
DObject.print();
Cout << endl;
Return 0 ;
}
Void bClass::print() const
{
Cout << x << " " << y << endl;
}
BClass::bClass(int a, int b)
{
X = a;
Y = b;
}
Void dClass::print() const
{
BClass:print();
Cout << " " << z << endl;
}
DClass::dClass(int a, int b, int c)
: bClass(a, b)
{
Z = c;
}

A) 2 3
2 3
B) 2 3
3 5 8
C) 3 5 8
3 5 8
D) 5 8
3 5 8
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
The ____ members of an object form its internal state.

A) private
B) protected
C) public
D) static
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
In ____________________, the derived class is derived from a single base class.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
Consider the following class definitions: class bClass
{
Public:
Void setX(int a);
//Postcondition: x = a;
Void print() const;
Private:
Int x;
};
Class dClass: public bClass
{
Public:
Void setXY(int a, int b);
//Postcondition: x = a; y = b;
Void print() const;
Private:
Int y;
};
Which of the following correctly sets the values of x and y?

A) void dClass::setXY(int a, int b)
{
BClass::setX(a);
Y = b;
}
B) void dClass::setXY(int a, int b)
{
X = a;
Y = b;
}
C) void dClass::setXY(int a, int b)
{
X = bClass::setX(a);
Y = bClass::setY(b);
}
D) void dClass::setXY(int a, int b)
{
X = bClass.setX(a);
B = y;
}
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
To define new classes in C++, you create new ____________________ files.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
The constructor of a derived class cannot directly access the ____________________ member variables of the base class.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
Consider the following class definitions: class bClass
{
Public:
Void setX(int);
Void print() const;
Private:
Int x;
};
Class dClass: public bClass
{
Public:
Void setXY(int, int);
Void print() const;
Private:
Int y;
};
Which of the following statements correctly redefines the member function print of bClass?

A) void dClass::print() const
{
DClass:print();
Cout << " " << y << endl;
}
B) void dClass::print() const
{
Cout << x << " " << y << endl;
}
C) void bClass::print() const
{
Cout << x << " " << y << endl;
}
D) void dClass::print() const
{
BClass::print();
Cout << "y = " << y << endl;
}
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
The term ____________________ is used to describe the ability to create new objects from existing objects.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
In the case of composition, the ____________________ name is used to invoke the constructor.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
In object-oriented design, we debug ____________________; in structured programming, we debug functions.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
In ____________________ (aggregation), one or more members of a class are objects of another class type.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
C++ provides ____________________ functions as a means to implement polymorphism in an inheritance hierarchy.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
In ____________________ polymorphism, the (data) type is left unspecified and then later instantiated.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
Objects are created when ____________________ variables are declared.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
The OOP terminology is influenced by the vocabulary of ____________________, the OOP language largely developed at a Xerox research center during the 1970s.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
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 50 flashcards in this deck.
Unlock Deck
k this deck
50
In C++, we implement ADT through the use of ____________________.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.