Exam 11: Inheritance and Composition
Exam 1: An Overview of Computers and Programming Languages50 Questions
Exam 2: Basic Elements of C50 Questions
Exam 3: Inputoutput50 Questions
Exam 4: Control Structures I Selection50 Questions
Exam 5: Control Structures II Repetition50 Questions
Exam 6: User-Defined Functions50 Questions
Exam 7: User-Defined Simple Data Types, Namespaces, and the String Type50 Questions
Exam 8: Arrays and Strings50 Questions
Exam 9: Records Structs50 Questions
Exam 10: Classes and Data Abstraction49 Questions
Exam 11: Inheritance and Composition50 Questions
Exam 12: Pointers, Classes, Virtual Functions, and Abstract Classes50 Questions
Exam 13: Overloading and Templates50 Questions
Exam 14: Exception Handling50 Questions
Exam 15: Recursion50 Questions
Exam 16: Searching, Sorting and the Vector Type50 Questions
Exam 17: Linked Lists50 Questions
Exam 18: Stacks and Queues50 Questions
Select questions type
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?
(Multiple Choice)
4.8/5
(25)
Existing classes, from which you create new classes, are called ____ classes.
(Multiple Choice)
4.8/5
(40)
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.
(Multiple Choice)
4.9/5
(37)
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;
}
(Multiple Choice)
4.7/5
(40)
In ____________________, the derived class is derived from a single base class.
(Short Answer)
5.0/5
(39)
Classes can create new classes from existing classes. This important feature ____.
(Multiple Choice)
4.8/5
(42)
C++ provides ____ functions as a means to implement polymorphism in an inheritance hierarchy, which allows the run-time selection of appropriate member functions.
(Multiple Choice)
4.8/5
(39)
A derived class cannot directly access public members of a base class.
(True/False)
4.9/5
(33)
The constructor of a derived class cannot directly access the ____________________ member variables of the base class.
(Short Answer)
4.8/5
(36)
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++?
(Multiple Choice)
4.9/5
(30)
A derived class can directly access the protected members of the base class.
(True/False)
4.8/5
(35)
Which of the following statements about inheritance is true if memberAccessSpecifier is protected?
(Multiple Choice)
4.8/5
(36)
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.
(Multiple Choice)
4.8/5
(37)
In multiple inheritance, the derived class has more than one base class.
(True/False)
4.7/5
(35)
____ is the ability to use the same expression to denote different operations.
(Multiple Choice)
4.9/5
(41)
Suppose that bClass is a class. Which of the following statements correctly derives the class dClass from bClass?
(Multiple Choice)
4.7/5
(35)
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?
(Multiple Choice)
4.9/5
(40)
Showing 21 - 40 of 50
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)