Question 7
Back to Exercise
Why is a class with a public getter and an unchecked setter for every data member considered weakly encapsulated?
- A Getters are slow
- B Callers can still set any value, so the class enforces no rules – it is barely different from public data Correct
- C Setters cannot be inline
- D It uses too much memory
Correct Answer: Option B
Encapsulation should protect invariants: validate in setters, or replace them with meaningful operations.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!