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!