Difficulty: Easy
Correct Answer: Private
Explanation:
Introduction / Context:
C++ distinguishes between classes and structs not by features but by defaults. Both support the same mechanisms: member functions, constructors, inheritance, templates, and so on. The key difference is the default access level of members and base classes when no explicit access specifier is provided. Remembering these defaults prevents accidental exposure or hiding of APIs.
Given Data / Assumptions:
Concept / Approach:
For a class, the default access specifier for members is private. For a struct, the default is public. This distinction also applies to base-class access in inheritance lists: class D : B implies private inheritance by default, while struct D : B implies public inheritance by default. Because the question explicitly asks about a class definition, the correct answer is private. Options like “Friend” are not access levels at all; friend is a separate language feature granting access to another function or class.
Step-by-Step Solution:
Verification / Alternative check:
Attempt to access an unlabelled member of a class from outside; the compiler rejects it. Mark the same member in a struct; it becomes accessible. Add public: to the class and access now succeeds, confirming the default.
Why Other Options Are Wrong:
Protected/Public — these are valid access levels, but they are not the defaults for class.
Friend — not an access specifier; it is a separate friendship declaration mechanism.
Common Pitfalls:
Final Answer:
Private
Discussion & Comments