In case of private inheritance in C++, which of the following correctly…
2018
In case of private inheritance in C++, which of the following correctly represents the accessibility of the data variables from second derived class?
- A.
Private variables: Yes, Protected variables: No, Public variables: Yes
- B.
Private variables: Yes, Protected variables: No, Public variables: No
- C.
Private variables: Yes, Protected variables: Yes, Public variables: Yes
- D.
Private variables: No, Protected variables: No, Public variables: No
Attempted by 104 students.
Show answer & explanation
Correct answer: D
In C++, private inheritance converts all public and protected members of the base class into private members of the derived class. Consequently, a second derived class cannot access these members because they are treated as private in the intermediate class. Original private members remain inaccessible to all derived classes regardless of inheritance type.