Question 4
Back to Exercise
What is the main reason to validate inside a setter?
- A Speed
- B To stop invalid values from ever being stored in the object Correct
- C To make the field public
- D Because the compiler requires it
Correct Answer: Option B
Every change goes through the setter, so one check protects the whole program.
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!