Vidyalelo
C++ Programming · Q49

Inheritance in C++

Programming · C++ Programming · question 49

Q49

What happens if the following C++ program is compiled? #include #include 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
Answer
C.
Error due to self call in show() function
D.
Error because show() function from class A is derived privately

Answer: Option B

Solution

Answer: Option B
No explanation is given for this question Let's Discuss on Board