Interview Questions

Cloning Objects that Contain Other Objects

Java Interview Questions for Cloning and Cloneable


(Continued from previous question...)

Cloning Objects that Contain Other Objects

If you wish to enable cloning of an object that includes object references as part of its instance data, you may have to do more work in clone() than just calling super.clone(). Clone should return an independent copy of the object. Object's clone() will copy the value of each instance variable from the original object into the corresponding instance variables of the copy object. If one of those variables is an object reference, the copy object will get a duplicate reference to the same object.

(Continued on next question...)

Other Interview Questions