← Quiz: Shallow and Deep Copy: all 10 questions
Quiz: Shallow and Deep Copy · Question 5 of 10
A class has fields String name, int age and List<Address addresses (Address is mutable). What must a correct deep copy…
A class has fields String name, int age and List<Address> addresses (Address is mutable). What must a correct deep copy do?
- A.Copy only the list reference
- B.Create a new String for name
- C.Create a new list but reuse the same Address objects
- D.Create a new list and a new copy of each Address in it
Answer & explanation
Correct answer: Create a new list and a new copy of each Address in it
Every mutable object reachable from the copy must be copied; String and int are safe to share.
Can you get the rest right without peeking?
Take the timed Quiz: Shallow and Deep Copy quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →