LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 7

Why getters and setters everywhere are weak Answer, explanation & discussion

  • MCQ
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links