Consider the following inheritance in C++ class BASE: class BASE { int B1;…

2022

Consider the following inheritance in C++ class BASE: class BASE { int B1; protected: int B2; public: ____ ____ void FUNB(); }; class DERIVED : public BASE { int D1; public: ____ ____ }; What will be the visibility modes of B2 and FUNB() in the derived class DERIVED?

Answer: A. B2 → protected, FUNB() → publicIn C++ public inheritance, each base-class member keeps its own access level when it becomes part of the derived class: a public base member stays public, a…

  1. A.

    B2 → protected, FUNB() → public

  2. B.

    B2 → protected, FUNB() → protected

  3. C.

    B2 → public, FUNB() → public

  4. D.

    B2 → private, FUNB() → protected

Attempted by 252 students.

Show answer & explanation

Correct answer: A

In C++ public inheritance, each base-class member keeps its own access level when it becomes part of the derived class: a public base member stays public, a protected base member stays protected, and a private base member is not accessible in the derived class at all. Public inheritance does not change an individual member's own specifier -- it only governs how the base's members are exposed through the derived class.

  1. BASE declares B2 in its protected: section, so B2's own access level in BASE is protected.

  2. BASE declares FUNB() in its public: section, so FUNB()'s own access level in BASE is public.

  3. DERIVED inherits from BASE with 'class DERIVED : public BASE', i.e. public inheritance, so each inherited member retains its own access level unchanged.

  4. Applying the rule: B2 remains protected in DERIVED, and FUNB() remains public in DERIVED.

Cross-check: a protected base member can never surface as public, and a public base member can never be demoted to protected or private, purely because of public inheritance -- the derived-class access level always matches the member's own base-class specifier. This confirms B2 stays protected and FUNB() stays public in DERIVED, matching only the pairing B2 -> protected, FUNB() -> public.

Explore the full course: Uppsc Polytechnic Lecturer 2025 Cs

Loading lesson…