Computer Programming Chapter 11
Which of the following is true about a derived class?
A derived class can redefine any public member function of the base class.
OOP implements ____.
OOD
Which of the following class definitions makes the public members of the class aClass become the public members of the class bClass?
class bClass: public aClass { //... };
Which of the following is a valid definition of the derived class bClass?
class bClass: public aClass { //... };
Suppose that bClass is a class. Which of the following statements correctly derives the class dClass from bClass?
class dClass: private bClass { //classMembersList };
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 ____.
classB::functionName();
Inheritance is an example of a(n) ____ relationship.
is-a
The ____ members of an object form its internal state.
private
The ____ members of an object form its external state.
public
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.
redefine
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?
void dClass::print() const { bClass::print(); cout << "y = " << y << endl; }
What is the output of the following program? #include <iostream> 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; }
2 3 3 5 8
____ is a "has-a" relationship.
Composition
____ is the ability to combine data, and operations on that data, in a single unit.
Encapsulation
____ is the ability to use the same expression to denote different operations.
Polymorphism
Which of the following is true about inheritance?
The public member variables of the base class become the public or private member variables of the derived class.
Which of the following statements about inheritance is true if memberAccessSpecifier is protected?
The public members of the base class become protected members of the derived class.
Existing classes, from which you create new classes, are called ____ classes.
base
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++?
dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; }
The new classes that we create from existing classes are called ____ classes.
derived
Classes can create new classes from existing classes. This important feature ____.
encourages code reuse
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.
overloaded
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.
private
C++ provides ____ functions as a means to implement polymorphism in an inheritance hierarchy, which allows the run-time selection of appropriate member functions.
virtual
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?
void dClass::setXY(int a, int b) { bClass::setX(a); y = b; }