Inheritance Quiz (CS)
Inheritance Quiz (CS)
Inheritance Quiz (CS)
Inheritance Quiz
* Required
1. 1. In multiple inheritance, the derived class has more than one base class. * 1 point
True
False
2. 2. The private members of a base class can be directly accessed by a derived class. 1 point
True
False
3. 3. A derived class cannot directly access public members of a base class. 1 point
True
False
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 1/23
4/6/23, 5:01 PM Inheritance Quiz
4. 4. If the derived class does not override a public member function of the base class, then in the definition of a 1 point
member function of the derived class, you may specify a call to that public member function by using the
name of the function and the appropriate parameter list.
True
False
5. 5. The constructors of a derived class can (directly) initialize only the (public data) members inherited from 1 point
the base class of the derived class.
True
False
6. 6. A call to the base class’s constructor is specified in the heading of the definition of a derived class 1 point
constructor.
True
False
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 2/23
4/6/23, 5:01 PM Inheritance Quiz
7. 7. The class io is the base class of the C++ stream classes istream and ostream. 1 point
True
False
8. 8. A derived class can directly access the protected members of the base class. 1 point
True
False
9. 9. In protected inheritance, public and protected members of the base class become the protected members 1 point
of the derived class.
True
False
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 3/23
4/6/23, 5:01 PM Inheritance Quiz
10. 10. If inheritance is private, all members of the base class, including private members, become private 1 point
members of the derived class.
True
False
is-a
has-a
handshaking
had-a
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 4/23
4/6/23, 5:01 PM Inheritance Quiz
12. 12. Classes can create new classes from existing classes. This important feature ____. 1 point
Inheritance
Encapsulation
Composition
Polymorphism
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 5/23
4/6/23, 5:01 PM Inheritance Quiz
14. 14. The new classes that we create from existing classes are called ____ classes. 1 point
sibling
base
derived
parent
15. 15. Existing classes, from which you create new classes, are called ____ classes. 1 point
child
base
sibling
derived
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 6/23
4/6/23, 5:01 PM Inheritance Quiz
16. 16. Suppose that bClass is a class. Which of the following statements correctly derives the class dClass 1 point
from bClass?
};
The class dClass is derived from the class bClass using the ____ type of inheritance.
public
private
protected
static
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 7/23
4/6/23, 5:01 PM Inheritance Quiz
18. 18. Which of the following is a valid definition of the derived class bClass? 1 point
All public member functions of the base class become the public member functions of the derived class.
All public member variables of the base class become the public member variables of the derived class.
All public members of the base class become the public members of the derived class.
The public member variables of the base class become the public or private member variables of the derived class.
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 8/23
4/6/23, 5:01 PM Inheritance Quiz
20. 20. Which of the following class definitions inherits the public members of the class aClass as the public 1 point
members of the class bClass?
A derived class can directly access any member variable of the base class.
A derived class can redefine any public member function of the base class.
A derived class can redefine any member function of the base class.
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 9/23
4/6/23, 5:01 PM Inheritance Quiz
22. 22. To ____ a public member function of a base class in the derived class, the corresponding function in the 1 point
derived class must have the same name, number, and types of parameters.
redefine
overload
rename
reuse
23. 23. If the corresponding functions in the base class and the derived class have the same name but different 1 point
reused
redefined
overloaded
overridden
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 10/23
4/6/23, 5:01 PM Inheritance Quiz
class bClass
{
public:
void setX(int);
void print() const;
private:
int x;
};
private:
int y;
};
Which of the following function definition correctly redefines the member function print of bClass in the
derived class dClass?
void dClass::print() const { dClass:print(); cout << " " << y << endl; }
void dClass::print() const { cout << x << " " << y << endl; }
void bClass::print() const { cout << x << " " << y << endl; }
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 11/23
4/6/23, 5:01 PM Inheritance Quiz
void dClass::print() const { bClass::print(); cout << "y = " << y << endl; }
25. 25. If the derived class classD overrides the public member function baseFunc of the base class classB, * 1 point
then to specify a call to baseFunc in classD, you use the statement ____.
classD:: baseFunc();
classB::baseFunc();
classD.baseFunc();
classB.baseFunc();
26. 26. Which of the following statements about inheritance is true if memberAccessSpecifier is protected? * 1 point
The private members of the base class become protected members of the derived class.
The derived class can directly access any member of the base class.
The public members of the base class become protected members of the derived class.
The protected members of the base class become private members of the derived class.
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 12/23
4/6/23, 5:01 PM Inheritance Quiz
class bClass
{
public:
void setX(int a);
//Postcondition: x = a;
void print() const;
private:
int x;
};
private:
int y;
};
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 14/23
4/6/23, 5:01 PM Inheritance Quiz
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;
};
dClass();
//Postcondition: x = 0; y = 0; z = 0 ;
dClass(double a, double b, double c);
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 15/23
4/6/23, 5:01 PM Inheritance Quiz
//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 c) { x = a; z = c; }
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 16/23
4/6/23, 5:01 PM Inheritance Quiz
#include <iostream>
class bClass
{
public:
void print() const;
bClass(int a = 0, int b = 0);
//Postcondition: x = a; y = b;
private:
int x;
int y;
};
private:
int z;
};
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 17/23
4/6/23, 5:01 PM Inheritance Quiz
int main()
{
bClass bObject(2, 3);
dClass dObject(3, 5, 8);
bObject.print();
cout<<endl;
dObject.print();
cout<<endl;
return 0 ;
}
bClass::bClass(int a, int b)
{
x = a;
y = b;
}
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 18/23
4/6/23, 5:01 PM Inheritance Quiz
2323
23358
358358
58358
30. 30. ____ is the ability to combine data, and operations on that data, in a single unit. * 1 point
Inheritance
Encapsulation
Polymorphism
Composition
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 19/23
4/6/23, 5:01 PM Inheritance Quiz
31. 31. In ____ the same expression is used to denote different operations. * 1 point
Inheritance
Encapsulation
Polymorphism
Composition
32. 33. C++ provides ____ functions as a means to implement polymorphism in an inheritance hierarchy, * 1 point
which allows the run-time selection of appropriate member functions.
redefined
overridden
virtual
overloaded
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 20/23
4/6/23, 5:01 PM Inheritance Quiz
33. 34. The ____ members of an object form its internal state. * 1 point
private
protected
public
static
34. 35. The ____ members of an object form its external state. * 1 point
private
public
protected
static
35. * 1 point
Option 1
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 21/23
4/6/23, 5:01 PM Inheritance Quiz
Forms
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 22/23
4/6/23, 5:01 PM Inheritance Quiz
https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 23/23