Short answer
Encapsulation protects class invariants by ensuring all state changes go through controlled paths, so the object can never be observed in an invalid state.
Explanation
A getter that returns a reference to an internal mutable collection or array leaks that protection — the caller can mutate it directly and bypass validation. The fix is to return an unmodifiable view (Collections.unmodifiableList), a defensive copy, or an immutable type, depending on the cost and copy semantics you need.
Common mistakes
- Saying private fields plus getters and setters for everything is encapsulation.
- Returning internal mutable collections directly from getters.