LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 14

The "tell, don't ask" principle Answer, explanation & discussion

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

Which code follows "tell, don't ask"?

  • A acc.setBalance(acc.getBalance() - 100)
  • B acc.withdraw(100) Correct
  • C if (acc.getBalance() > 100) acc.balance -= 100
  • D Account.balance -= 100
Correct Answer: Option B

The account applies its own rules.

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