0% found this document useful (0 votes)
6 views

C++ Inheritance test _ C++ Practice Test _ Studytonight

The document is a C++ inheritance test that includes multiple-choice questions covering various concepts of inheritance in C++. It tests knowledge on member accessibility, multiple inheritance, constructor behavior, and specific code outputs. The test provides correct answers for each question, aiding in the understanding of inheritance in C++.

Uploaded by

30971
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

C++ Inheritance test _ C++ Practice Test _ Studytonight

The document is a C++ inheritance test that includes multiple-choice questions covering various concepts of inheritance in C++. It tests knowledge on member accessibility, multiple inheritance, constructor behavior, and specific code outputs. The test provides correct answers for each question, aiding in the understanding of inheritance in C++.

Uploaded by

30971
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

9/1/2019 C++ Inheritance test | C++ Practice Test | Studytonight

(/) 

C++ Inheritance Test


This Test will cover Inheritance concepts of C++.

Q. For below code snippet, the public and protected members of Superclass
becomes _________ members of Sub class.

class subclass : protected Superclass

A. public

B. private

C. protected

D. None of the above

Correct Answer : OPTION C, Protected

Q. What will be the output of following code ?

https://www.studytonight.com/cpp/tests/3# 1/7
9/1/2019 C++ Inheritance test | C++ Practice Test | Studytonight

#include <iostream>
using namespace std;

class Animal
{
public:
int legs = 4;
};

class Dog : public Animal


{
public:
int tail = 1;
};

int main()
{
Dog d;
cout << d.legs;
cout << d.tail;
}

A. error

B. 44

C. 40

D. 41

Correct Answer : OPTION D, 4 1

Q. Do base class and its object have any knowledge about any classes derived
from base class?

A. Yes

B. No

Correct Answer : OPTION B, No

Q. What is Multiple Inheritance ?

https://www.studytonight.com/cpp/tests/3# 2/7
9/1/2019 C++ Inheritance test | C++ Practice Test | Studytonight

A. Deriving a class from Base class

B. Deriving a derived class from two and more class

C. Deriving two or more class from a base class

D. None of the above

Correct Answer : OPTION B, Deriving a derived class from two and more class.

Q. Whenever you create derived class object, first the base class default
constructor is executed and then the derived class constructor?

A. true

B. false

Correct Answer : OPTION A

Q. Which of the following Function is not inherited?

A. constructor

B. destructor

C. Assignment operator(=)

D. All of the above

Correct Answer : OPTION D, All of the above(constructor, destructor, Assignment operator(=) )

Q. What will be the output of following code?

https://www.studytonight.com/cpp/tests/3# 3/7
9/1/2019 C++ Inheritance test | C++ Practice Test | Studytonight

#include <iostream>
using namespace std;

class Base
{
public:
Base() { cout << "Base"; }
};

class Derived : public Base


{
public:
Derived(int i) { cout << i; }
};

int main()
{
Derived d2(10);
return 0;
}

A. Base10

B. 10

C. 10Base

D. error

Correct Answer : OPTION A

Q. What will be the output of following code?

https://www.studytonight.com/cpp/tests/3# 4/7
9/1/2019 C++ Inheritance test | C++ Practice Test | Studytonight

#include <iostream>
using namespace std;

class A
{
int x;
};

class B : public A
{
public:
void show()
{
x=10;
cout << x;
}
};

int main()
{
B b;
b.show();
return 0;
}

A. 10

B. 0

C. error

D. garbage value

Correct Answer : OPTION C, error

Q. Which symbol is used to create multiple inheritance ?

A. Dot(.)

B. Comma(,)

C. Colon(:)

D. None of the above

https://www.studytonight.com/cpp/tests/3# 5/7
9/1/2019 C++ Inheritance test | C++ Practice Test | Studytonight

Correct Answer : OPTION B, Comma(,)

Q. All members of a Base class including private member are inherited in


Derived class.

A. true

B. false

Correct Answer : OPTION A, true. Private members are inherited but are not accessible.

SUBMIT TEST ()

What is Studytonight?

About Us (/about)

Authors (/authors)

Collaborate (/collaborate)

Testimonials (/testimonials)

Privacy Policy (/privacy)

Terms (/terms)

Contact Us (/contact)

Suggest (/suggest)

Tutorials

Android (/android)

Core Java (/java)

C++ (/cpp)

Data Structures (/data-structures)

Python (/python)

Network Programming (/network-programming-in-python)

DBMS & SQL (/dbms)

https://www.studytonight.com/cpp/tests/3# 6/7
9/1/2019 C++ Inheritance test | C++ Practice Test | Studytonight

Servlet (/servlet)

More... (/library)

Tests

Core Java (/tests)

Android (/tests/?subject=android)

C++ (/tests?/?subject=cpp)

DBMS (/tests?/?subject=dbms)

C Language (/tests?/?subject=c)

More... (/tests)

Learn to Code

HTML (/code/html)

CSS (/cascading-style-sheet/)

Website Development (/code/playground)

Java Interview Question (/ ashcards/Java)

C++ Interview Question (/ ashcards/Cpp)

OS Interview Question (/ ashcards/OS)

DBMS Interview Question (/ ashcards/Sql)

More... (/ ashcards)

https://www.studytonight.com/cpp/tests/3# 7/7

You might also like