← Quiz: Shallow and Deep Copy: all 10 questions
Quiz: Shallow and Deep Copy · Question 2 of 10
In a shallow copy, what happens to a field that refers to another object?
In a shallow copy, what happens to a field that refers to another object?
- A.The referred object is copied too
- B.Only the reference is copied, so both objects share the inner object
- C.The field is set to null
- D.The field is skipped
Answer & explanation
Correct answer: Only the reference is copied, so both objects share the inner object
A shallow copy copies field values; for a reference field, the value is the reference.
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 →