C++ Inheritance test _ C++ Practice Test _ Studytonight
C++ Inheritance test _ C++ Practice Test _ Studytonight
(/)
Q. For below code snippet, the public and protected members of Superclass
becomes _________ members of Sub class.
A. public
B. private
C. protected
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;
};
int main()
{
Dog d;
cout << d.legs;
cout << d.tail;
}
A. error
B. 44
C. 40
D. 41
Q. Do base class and its object have any knowledge about any classes derived
from base class?
A. Yes
B. No
https://www.studytonight.com/cpp/tests/3# 2/7
9/1/2019 C++ Inheritance test | C++ Practice Test | Studytonight
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
A. constructor
B. destructor
C. Assignment operator(=)
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"; }
};
int main()
{
Derived d2(10);
return 0;
}
A. Base10
B. 10
C. 10Base
D. error
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
A. Dot(.)
B. Comma(,)
C. Colon(:)
https://www.studytonight.com/cpp/tests/3# 5/7
9/1/2019 C++ Inheritance test | C++ Practice Test | Studytonight
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)
Terms (/terms)
Contact Us (/contact)
Suggest (/suggest)
Tutorials
Android (/android)
C++ (/cpp)
Python (/python)
https://www.studytonight.com/cpp/tests/3# 6/7
9/1/2019 C++ Inheritance test | C++ Practice Test | Studytonight
Servlet (/servlet)
More... (/library)
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/)
More... (/ ashcards)
https://www.studytonight.com/cpp/tests/3# 7/7