Which of the following can be considered as the members that can be inherited…
2023
Which of the following can be considered as the members that can be inherited but not accessible within the derived class?
Answer: C. Private — In C++-style object-oriented programming (the convention this class of exam question follows), inheritance and access control are two independent things: an…
- A.
Public
- B.
Protected
- C.
Private
- D.
More than one of these access specifiers
- E.
None of these access specifiers
Attempted by 668 students.
Show answer & explanation
Correct answer: C
In C++-style object-oriented programming (the convention this class of exam question follows), inheritance and access control are two independent things: an access specifier (public, protected, or private) decides whether a base-class member's name can be referenced directly from a piece of code, while inheritance decides whether that member becomes part of the derived class's object at all. A member can therefore be inherited -- physically present in every derived-class object -- without the derived class's own code being permitted to reference it directly by name.
Applying this rule to each access specifier shows a clear pattern:
Access specifier | Inherited into the derived object | Directly nameable in the derived class's own code |
|---|---|---|
Public | Yes | Yes |
Protected | Yes | Yes |
Private | Yes | No |
Public and protected members are both inherited and directly nameable inside the derived class, so neither matches a pattern of 'inherited but not accessible'. Private members are the only row where 'inherited' is paired with 'not directly nameable'.
This matches the standard C++ access-control rule that this style of exam question follows: derived-class code can call an inherited public or protected member directly by name, but can reach an inherited private member only indirectly, through a public or protected method that the base class itself provides -- it can never write the private member's name directly inside the derived class.
So the members that are inherited into a derived class but not directly accessible within it are the Private members.