LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 11

When a defensive copy is unnecessary Answer, explanation & discussion

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

For which field type is a defensive copy unnecessary?

  • A int[]
  • B String (immutable) Correct
  • C ArrayList<String>
  • D java.util.Date
Correct Answer: Option B

Immutable objects such as String, Integer and LocalDate can be shared safely.

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