Now, let's say that this attribute was reference to object of type "Dog". So your new object will have copy of this reference, which will point to object of type "Dog", but it will be the same Dog instance. Cloning owner will not create new Dog instance.
Deep copy ensures, that every referenced object will be cloned as well. So cloning owner in this case would create a new dog for him and you would have 2 owners and 2 dogs.
Joined: Jun 07, 2007
I understand book defination If a shallow copy is performed on obj-1 then it is copied but its contained objects are not. The contained objects Obj-1 and Obj-2 are affected by changes to cloned Obj-2. Java supports shallow cloning of objects by default when a class implements the java.lang.Cloneable interface. If a deep copy is performed on obj-1 then not only obj-1 has been copied but the objects contained within it have been copied as well. Serialization can be used to achieve deep cloning. Deep cloning through serialization is faster to develop and easier to maintain but carries a performance overhead.
I need more real life example if you can think of? and senerio where to use it.
Joined: May 04, 2007
Clone of this Car should have its own wheels.
Clone of twin (his brother or sister) should have same mother.
It depends on situation and what are you trying to accomplish.