Question
Which statement about Encapsulation is the strongest interview answer?
- Encapsulation is mostly a naming style choice and has little effect on runtime or design.
- Encapsulation exists mainly to reduce the number of Java files in a project.
- Encapsulation protects invariants by controlling how internal state is read and modified.
- Encapsulation matters only for frontend frameworks, not for core Java applications.
Hint
Start with the core rule behind Encapsulation.
Answer and rationale
Correct answer: C. Encapsulation protects invariants by controlling how internal state is read and modified.
Encapsulation protects invariants by controlling how internal state is read and modified. This is the base concept interviewers commonly test first.
Track: Java