← 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 →- Q1. What does this print? (code)
- Q2. In a shallow copy, what happens to a field that refers to another object?
- Q3. What does super.clone() do inside a class that implements Cloneable?
- Q4. What does this print? (code)
- Q5. A class has fields String name, int age and List<Address addresses (Address is mutable). What must a correct deep copy do?
- Q6. Which statement about Cloneable is true?
- Q7. What does this print? (code)
- Q8. Why do many Java developers prefer a copy constructor over clone()?
- Q9. When is a shallow copy completely safe?
- Q10. Student b = a.clone(); (a correct shallow clone). Which of these is true?