Inheritance Quiz (CS)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

4/6/23, 5:01 PM Inheritance Quiz

Inheritance Quiz
* Required

1. 1. In multiple inheritance, the derived class has more than one base class. * 1 point

Mark only one oval.

True

False

2. 2. The private members of a base class can be directly accessed by a derived class. 1 point

Mark only one oval.

True

False

3. 3. A derived class cannot directly access public members of a base class. 1 point

Mark only one oval.

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.

Mark only one oval.

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.

Mark only one oval.

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.

Mark only one oval.

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

Mark only one oval.

True

False

8. 8. A derived class can directly access the protected members of the base class. 1 point

Mark only one oval.

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.

Mark only one oval.

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.

Mark only one oval.

True

False

11. 11. Inheritance is an example of a(n) ____ relationship. 1 point

Mark only one oval.

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

Mark only one oval.

encourages code reuse

aids the separation of data and operations

provides public access to the internal state of an object

results in more software complexity

13. 13. ____ is a “has-a” relationship. 1 point

Mark only one oval.

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

Mark only one oval.

sibling

base

derived

parent

15. 15. Existing classes, from which you create new classes, are called ____ classes. 1 point

Mark only one oval.

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?

Mark only one oval.

class dClass:: public bClass { //classMembersList }; ​

class dClass: private bClass { //classMembersList };

class dClass:: protected bClass { //classMembersList };

class bClass: public dClass { //classMembersList };

17. 17. Consider the following class definition: 1 point

class dClass: bClass {

//class members list

};
The class dClass is derived from the class bClass using the ____ type of inheritance.

Mark only one oval.

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

Mark only one oval.

class aClass: public bClass { //... };

class bClass: public aClass { //... };

class aClass::bClass { //... };

class bClass::aClass { //... }

19. 19. Which of the following is true about inheritance? 1 point

Mark only one oval.

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?

Mark only one oval.

class aClass: public bClass { //... };

class bClass: public aClass { //... };

class bClass: aClass { //... };

class aClass: bClass { //... };

21. 21. Which of the following is true about a derived class? 1 point

Mark only one oval.

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 have at most one 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.

Mark only one oval.

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

sets of parameters, then this function is ____ in the derived class.

Mark only one oval.

reused

redefined

overloaded

overridden

https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 10/23
4/6/23, 5:01 PM Inheritance Quiz

24. 24. Consider the following class definitions: 1 point


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  function definition correctly redefines the member function print of bClass in the
derived class dClass?

Mark only one oval.

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 ____.

Mark only one oval.

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

Mark only one oval.

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

27. 27. Consider the following class definitions: * 1 point


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?  

Mark only one oval.

void dClass::setXY(int a, int b) { bClass::setX(a); y = b; }

void dClass::setXY(int a, int b) { x = a; y = b; }

void dClass::setXY(int a, int b) { x = bClass::setX(a); y = bClass::setY(b); }


https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 13/23
4/6/23, 5:01 PM Inheritance Quiz

void dClass::setXY(int a, int b) { x = bClass.setX(a); b = y; }

https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 14/23
4/6/23, 5:01 PM Inheritance Quiz

28. 28. Consider the following class definitions: * 1 point

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);
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++?

Mark only one oval.

dClass::dClass(double a, double b, double c) : bClass() { x = a; y = b; z = c; }

dClass::dClass(double a, double c) { x = a; z = c; }

dClass::dClass(double a, double b) : bClass() { x = a; y = b; }

dClass::dClass(double a, double b, double c) : bClass(a, b) { z = c; }

https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 16/23
4/6/23, 5:01 PM Inheritance Quiz

29. 29. What is the output of the following program? * 1 point

#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;
};

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 ;
}

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;
}

https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 18/23
4/6/23, 5:01 PM Inheritance Quiz

dClass::dClass(int a, int b, int c)


: bClass(a, b)
{
  z = c;
Mark only one oval.
}  

2323

23358

358358

58358

30. 30. ____ is the ability to combine data, and operations on that data, in a single unit. * 1 point

Mark only one oval.

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

Mark only one oval.

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.

Mark only one oval.

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

Mark only one oval.

private

protected

public

static

34. 35. The ____ members of an object form its external state. * 1 point

Mark only one oval.

private

public

protected

static

35. * 1 point

Mark only one oval.

Option 1

https://docs.google.com/forms/d/1GeJ7-UYBo8wEyMtr6gIVMG95BY3r1HBXCVjz50bQDNo/edit 21/23
4/6/23, 5:01 PM Inheritance Quiz

This content is neither created nor endorsed by Google.

 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

You might also like