Chapter 9 (Inheritance) - Questions
Composition is a ___________ form of ____________.
stronger, aggregation
If a base class and a derived class each include a member function with the same name, which member function will be called by an object of the derived class, assuming the scope-resolution operator is not used?
the one in the derived class
True or false: A class D can be derived from a class C, which is derived from a class B, which is derived from a class A.
true
True or false: If no constructors are specified for a derived class, objects of the derived class will use the constructors in the base class.
true
True or false: It is sometimes useful to specify a class from which no objects will ever be created.
true
If a base class contains a member function basefunc(), and a derived class does not contain a function with this name, can an object of the derived class access basefunc()?
yes (assuming basefunc is not private)
Assume a class Derv derived from a base class Base. Both classes contain a member function func() that takes no arguments. Write a statement to go in a member function of Derv that calls func() in the base class.
Base::func();
Write a declarator for a no-argument constructor of the derived class Bosworth of Question 4 that calls a no-argument constructor in the base class Alphonso.
Bosworth() : Alphonso() { }
Assume that the classes mentioned in Question 4 and the class Alphonso contain a member function called alfunc(). Write a statement that allows object BosworthObj of class Bosworth to access alfunc().
BosworthObj.alfunc();
Assume that there is a class Derv that is derived from a base class Base. Write the declarator for a derived-class constructor that takes one argument and passes this argument along to the constructor in the base class.
Derv(int arg) : Base(arg)
To be accessed from a member function of the derived class, data or functions in the base class must be public or _________.
protected
Assume a class Derv that is privately derived from class Base. An object of class Derv located in main() can access a. public members of Derv. b. protected members of Derv. c. private members of Derv. d. public members of Base. e. protected members of Base. f. private members of Base.
a
Inheritance is a way to a. make general classes into more specific classes. b. pass arguments to objects of classes. c. add features to existing classes without rewriting them. d. improve data hiding and encapsulation.
a, c
Advantages of inheritance include a. providing class growth through natural selection. b. facilitating class libraries. c. avoiding the rewriting of code. d. providing a useful conceptual framework.
b, c, d
A class hierarchy a. shows the same relationships as an organization chart. b. describes "has a" relationships. c. describes "is a kind of" relationships. d. shows the same relationships as a family tree.
c
The scope-resolution operator usually a. limits the visibility of variables to a certain function. b. tells what base class a class is derived from. c. specifies a particular class. d. resolves ambiguities.
c, d
Write the first line of the specifier for a class Bosworth that is publicly derived from a class Alphonso.
class Bosworth : public Alphonso
Write the first line of a specifier for a class Tire that is derived from class Wheel and from class Rubber.
class Tire : public Wheel, public Rubber
Aggregation is a. a stronger form of instantiation. b. a stronger form of generalization. c. a stronger form of composition. d. a "has a" relationship.
d
A "child" class is said to be _________ from a base class.
derived
True or false: Adding a derived class to a base class requires fundamental changes to the base class.
false
True or false: It is illegal to make objects of one class members of another class.
false
True or false: the arrow representing generalization points to the more specific class.
false
In the UML, inheritance is called _____________.
generalization
