LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 8

Returning a private list from a getter Answer, explanation & discussion

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

A getter returns a private ArrayList field directly. What is the risk?

  • A None, the field is private
  • B Callers can modify the list and bypass the class's rules Correct
  • C It does not compile
  • D The list is copied automatically
Correct Answer: Option B

private protects the variable, not the object it refers to.

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