ProgrammingHardIBM · Deloitte pattern

class D : private B { ... }; where B has public int x, protected int y and private int z. Which is correct?

  1. A. Inside D's member functions x, y and z are accessible
  2. B. None of x, y, z is accessible inside D
  3. C. x stays public in D, so main can use d.x
  4. D. Inside D's member functions x and y are accessible, but main cannot access x through a D object

Correct answer: D. Inside D's member functions x and y are accessible, but main cannot access x through a D object

Private inheritance turns B's public and protected members into private members of D: usable inside D, hidden from outside. B's private z is never accessible to a derived class.

More OOP with C++ and Java questions

Exams that ask this topic