Exam4Training

What happens when you attempt to compile and run the following code?

What happens when you attempt to compile and run the following code?

#include <iostream>

#include <string>

using namespace std;

class A {

public:

A() { cout << "A0 ";}

A(string s) { cout << "A1";}

};

class B : public A {

public:

B() { cout << "B0 ";}

B(string s) { cout << "B1 ";}

};

class C : private B {

public:

C() { cout << "C0 ";}

C(string s) { cout << "C1 ";}

};

int main () {

B b1;

C c1;

return 0;

}
A . It prints: A0 B0 A0 B1 A0 C0 A0 C1
B.It prints: B0 B1 C0 C1
C.It prints: A0 B0 A0 B0 C0
D.It prints: B0 B1

Answer: C

Exit mobile version