Deck 4: Inheritance and Class Hierarchies

Full screen (f)
exit full mode
Question
The objects of a derived class __________ the original data fields and members of a base class.
Use Space or
up arrow
down arrow
to flip the card.
Question
Classes can be arranged in a hierarchy, with a top-level __________ class.
Question
Objects further down the hierarchy are more complex and less general than those further up.
Question
The __________ relationship between classes means that every instance of one class is or may be associated with one or more instances of the other class (but not necessarily the other way around).
Question
A Ford Model-T automobile is in a "has-a" relationship with __________.

A) automobiles
B) antique automobiles
C) a Rolls Royce Silver Ghost
D) an engine
Question
According to the inheritance structure defined by the code fragment below, an Airplane is a kind of Jet_Plane.
class Jet_Plane : public Airplane {
private:
int num_engines;
Jet_Engine jets[4];
// ...
};
Question
If the execution of any constructor in a derived class does not invoke a base class constructor, C++ automatically invokes the no-parameter constructor for the __________ class.

A) sub
B) base
C) child
D) subordinate
Question
In general, it is better to use __________ visibility, because derived classes may be written by different programmers, and it is always a good practice to restrict and control access to the base-class data fields.

A) protected
B) public
C) package
D) private
Question
Member functions generally have __________ visibility, so we should be able to access a member function that is inherited.
Question
Having multiple member functions with the same name but different signatures in a class is called member function __________.
Question
Suppose two Clock class functions named get_military_time use the following headers:
Std::string get_military_time (int hours, int minutes);
Std::string get_military_time (int hours, int minutes, int seconds);
The get_military__time member function is said to be __________.

A) overloaded
B) overridden
C) downcast
D) extended
Question
If a member function is declared __________, then when it is called through a pointer (or reference) variable the actual member function will be determined at run time and based on the type of the object pointed to (or referenced).

A) public
B) private
C) virtual
D) protected
Question
The C++ compiler can assign object addresses to pointers at program run-time.
Question
A(n) __________ function is a virtual function that is declared but for which no body (definition) is provided.
Question
Which of the following statements is a valid abstract member function declaration for class Food?

A) abstract double percent_protein();
B) abstract double percent_protein() const = 0;
C) virtual double percent_protein();
D) virtual double percent_protein() const = 0;
Question
A pointer variable (l-value) that is of type pointer-to- __________ class may point to a derived object (r-value).

A) sub
B) child
C) base
D) derived
Question
Given that the Lap_Top class derives from Computer class, which of the following pointer declarations is legal?

A) Lap_Top* a_laptop = new Computer( ... );
B) Computer* a_computer = new Lap_Top( ... );
C) Lap_Top* a_laptop = Computer( ... );
D) *a_computer = new LapTop( ... );
Question
If you dynamically cast a pointer to a lower type object, the lower type object is promoted to a higher type.
Question
Complete the header for class Artist, which inherits from both class Musician and class Writer.
class Artist __________
Question
__________ is a process that resolves name conflicts by collecting common data fields and member functions into a common base class.

A) Overloading
B) Refactoring
C) Overriding
D) Casting
Question
__________ are used to group collections of declarations into a functional unit.
Question
At the top of the level of the namespace hierarchy resides the global namespace, whose name is effectively the __________ string.
Question
The statement __________ creates an object of type stack as defined in the optimize namespace.
Class stack { ... }; // Defined in the global namespace
Namespace optimize {
Class stack { ... }; // Defined in the optimize namespace
}

A) stack aStack;
B) std::stack aStack;
C) optimize aStack;
D) optimize::stack aStack;
Question
To access a single name from the namespace in which it was declared requires a using __________ .
Question
Private visibility is for members of a class that should not be accessible to anyone but the class, not even classes that extend it.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/25
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 4: Inheritance and Class Hierarchies
1
The objects of a derived class __________ the original data fields and members of a base class.
inherit
2
Classes can be arranged in a hierarchy, with a top-level __________ class.
base
3
Objects further down the hierarchy are more complex and less general than those further up.
True
4
The __________ relationship between classes means that every instance of one class is or may be associated with one or more instances of the other class (but not necessarily the other way around).
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
5
A Ford Model-T automobile is in a "has-a" relationship with __________.

A) automobiles
B) antique automobiles
C) a Rolls Royce Silver Ghost
D) an engine
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
6
According to the inheritance structure defined by the code fragment below, an Airplane is a kind of Jet_Plane.
class Jet_Plane : public Airplane {
private:
int num_engines;
Jet_Engine jets[4];
// ...
};
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
7
If the execution of any constructor in a derived class does not invoke a base class constructor, C++ automatically invokes the no-parameter constructor for the __________ class.

A) sub
B) base
C) child
D) subordinate
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
8
In general, it is better to use __________ visibility, because derived classes may be written by different programmers, and it is always a good practice to restrict and control access to the base-class data fields.

A) protected
B) public
C) package
D) private
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
9
Member functions generally have __________ visibility, so we should be able to access a member function that is inherited.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
10
Having multiple member functions with the same name but different signatures in a class is called member function __________.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
11
Suppose two Clock class functions named get_military_time use the following headers:
Std::string get_military_time (int hours, int minutes);
Std::string get_military_time (int hours, int minutes, int seconds);
The get_military__time member function is said to be __________.

A) overloaded
B) overridden
C) downcast
D) extended
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
12
If a member function is declared __________, then when it is called through a pointer (or reference) variable the actual member function will be determined at run time and based on the type of the object pointed to (or referenced).

A) public
B) private
C) virtual
D) protected
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
13
The C++ compiler can assign object addresses to pointers at program run-time.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
14
A(n) __________ function is a virtual function that is declared but for which no body (definition) is provided.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following statements is a valid abstract member function declaration for class Food?

A) abstract double percent_protein();
B) abstract double percent_protein() const = 0;
C) virtual double percent_protein();
D) virtual double percent_protein() const = 0;
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
16
A pointer variable (l-value) that is of type pointer-to- __________ class may point to a derived object (r-value).

A) sub
B) child
C) base
D) derived
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
17
Given that the Lap_Top class derives from Computer class, which of the following pointer declarations is legal?

A) Lap_Top* a_laptop = new Computer( ... );
B) Computer* a_computer = new Lap_Top( ... );
C) Lap_Top* a_laptop = Computer( ... );
D) *a_computer = new LapTop( ... );
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
18
If you dynamically cast a pointer to a lower type object, the lower type object is promoted to a higher type.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
19
Complete the header for class Artist, which inherits from both class Musician and class Writer.
class Artist __________
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
20
__________ is a process that resolves name conflicts by collecting common data fields and member functions into a common base class.

A) Overloading
B) Refactoring
C) Overriding
D) Casting
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
21
__________ are used to group collections of declarations into a functional unit.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
22
At the top of the level of the namespace hierarchy resides the global namespace, whose name is effectively the __________ string.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
23
The statement __________ creates an object of type stack as defined in the optimize namespace.
Class stack { ... }; // Defined in the global namespace
Namespace optimize {
Class stack { ... }; // Defined in the optimize namespace
}

A) stack aStack;
B) std::stack aStack;
C) optimize aStack;
D) optimize::stack aStack;
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
24
To access a single name from the namespace in which it was declared requires a using __________ .
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
25
Private visibility is for members of a class that should not be accessible to anyone but the class, not even classes that extend it.
Unlock Deck
Unlock for access to all 25 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 25 flashcards in this deck.