🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← All topics

Quiz: Shallow and Deep Copy: questions with answers

10 questions, each with the answer and a short explanation.

Take the timed quiz + get a certificate →
  1. Q1. What does this print? (code)
  2. Q2. In a shallow copy, what happens to a field that refers to another object?
  3. Q3. What does super.clone() do inside a class that implements Cloneable?
  4. Q4. What does this print? (code)
  5. Q5. A class has fields String name, int age and List<Address addresses (Address is mutable). What must a correct deep copy do?
  6. Q6. Which statement about Cloneable is true?
  7. Q7. What does this print? (code)
  8. Q8. Why do many Java developers prefer a copy constructor over clone()?
  9. Q9. When is a shallow copy completely safe?
  10. Q10. Student b = a.clone(); (a correct shallow clone). Which of these is true?