LearnFrenzy
Sign in Take a free test

Encapsulation · Encapsulation MCQ · Question 9

What a defensive copy is Answer, explanation & discussion

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

What is a defensive copy?

  • A A backup file
  • B A copy of a mutable object made when it enters or leaves a class, so outside code cannot alter internal state Correct
  • C A clone of the whole class
  • D A copy made by the garbage collector
Correct Answer: Option B

For example new ArrayList<>(list), arr.clone() or List.copyOf(list).

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