What will be the output of the following C++ code?
#include <iostream>
#include <string>
using namespace std;
class A
{
float d;
public:
A(){
cout<<"Constructor of class A\n";
}
};
class B: public A
{
int a = 15;
public:
B(){
cout<<"Constructor of class B\n";
}
};
int main(int argc, char const *argv[])
{
B b;
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class A
{
float d;
public:
A(){
cout<<"Constructor of class A\n";
}
};
class B: public A
{
int a = 15;
public:
B(){
cout<<"Constructor of class B\n";
}
};
int main(int argc, char const *argv[])
{
B b;
return 0;
}A. Constructor of class A
Constructor of class B
B. Constructor of class A
C. Constructor of class B
D. Constructor of class B
Constructor of class A
Answer: Option A
Related Questions on Inheritance in C plus plus
A. Multilevel inheritance
B. Hierarchical inheritance
C. Multiple inheritance
D. Single inheritance
A. public
B. private
C. friend
D. protected
What is the process of defining a new class based on an existing class in C++ called?
A. Inheritance
B. Composition
C. Encapsulation
D. Polymorphism

Join The Discussion