🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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?

  1. A.Copy only the list reference
  2. B.Create a new String for name
  3. C.Create a new list but reuse the same Address objects
  4. 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 →