LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 18

Constructors and setter validation Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 18 Back to Exercise

Why might a constructor call the class's own (final or private) validating setters?

  • A Constructors cannot assign fields
  • B To reuse the same validation, so objects are valid from the start Correct
  • C For speed
  • D To make the fields public
Correct Answer: Option B

Keep such setters final so subclasses cannot change them during construction.

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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links