What happens if the following C++ program is compiled?
#include <iostream>
#include <string>
using namespace std;
class A
{
int a;
public:
A(){
a = 0;
}
void show(){
a++;
cout<<"a: "<<a<<endl;
}
};
class B: private A
{
public:
void show(){
show();
}
};
int main(int argc, char const *argv[])
{
B b;
b.show();
return 0;
}
#include <iostream>
#include <string>
using namespace std;
class A
{
int a;
public:
A(){
a = 0;
}
void show(){
a++;
cout<<"a: "<<a<<endl;
}
};
class B: private A
{
public:
void show(){
show();
}
};
int main(int argc, char const *argv[])
{
B b;
b.show();
return 0;
}A. Error because of the conflicts between two show() function in class B
B. Program will compile successfully
C. Error due to self call in show() function
D. Error because show() function from class A is derived privately
Answer: Option B
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