ProgrammingHardProduct-company placement · C++

Which line fails to compile?

Which line fails to compile?
class B { public: void f() { cout << "f"; } void g() { cout << "g"; } };
class D : private B { public: using B::f; };
int main() {
    D d;
    d.f();   // L1
    d.g();   // L2
}
  1. A. L1 only
  2. B. Both
  3. C. L2 only
  4. D. Neither

Correct answer: C. L2 only

Private inheritance makes all of B's members private in D. A using-declaration in D's public section re-exposes f only; g stays inaccessible from main.

More OOP with C++ and Java questions

Exams that ask this topic