Difficulty: Easy
Correct Answer: public
Explanation:
Introduction / Context:
C++ supports access control to encapsulate class internals. Members declared in different sections (public, private, protected) have different visibility to client code. Knowing which section grants direct access determines how you design APIs and maintain invariants.
Given Data / Assumptions:
Concept / Approach:
Members declared under the public: specifier are accessible to all code with visibility to the class. This is how interfaces are exposed. In contrast, private members are not directly accessible outside the class; protected members are accessible to the class, its friends, and derived classes. Nonstandard labels like common or exposed are not part of C++ syntax.
Step-by-Step Solution:
Locate the access specifiers in a class: public:, protected:, private:.Place the data member under public: if it must be directly accessible by outside code.Alternatively, prefer private: and provide getters/setters to preserve invariants, but that is beyond the question's scope.Thus, the correct section for direct exposure is public.
Verification / Alternative check:
Attempt to access a private member from non-member code and observe compilation failure; change it to public and the access succeeds, confirming the rule.
Why Other Options Are Wrong:
Common Pitfalls:
Overusing public data breaks encapsulation; prefer public functions and keep data private unless a plain data structure is intended.
Final Answer:
public.
Discussion & Comments