1Z0-811 · Question #12
Which two Java reserved words are used to implement encapsulation?
The correct answer is C. public. The question states "which two" but marks only C - this appears to be an error. The correct pair is C (public) and E (private), which together are the foundation of encapsulation. Encapsulation works by declaring fields private to hide them from direct external access, then…
Question
Options
- Afinal
- Bstatic
- Cpublic
- Dextends
- Eprivate
How the community answered
(31 responses)- A3% (1)
- C94% (29)
- D3% (1)
Explanation
The question states "which two" but marks only C - this appears to be an error. The correct pair is C (public) and E (private), which together are the foundation of encapsulation.
Encapsulation works by declaring fields private to hide them from direct external access, then exposing controlled access through public getter/setter methods. Without both modifiers working together, you cannot achieve the "hide data, expose behavior" pattern encapsulation requires.
Why the other options are wrong:
- A (final) - prevents reassignment or subclassing, but has nothing to do with hiding or exposing data
- B (static) - ties a member to the class rather than an instance; unrelated to access control
- D (extends) - enables inheritance, which is a separate OOP pillar from encapsulation
Memory tip: Think of encapsulation as a vault - private is the locked door keeping fields hidden, and public is the controlled window (getters/setters) that lets the outside world interact safely. If your exam lists only C as correct, flag the question - the canonical answer is C + E.
Topics
Community Discussion
No community discussion yet for this question.