Java provides a mechanism for creating copies of objects called cloning.
two ways ------ shallow copy and deep copy
Shallow copy is a bit-wise copy of an object. A new object is created that has an exact copy of the values in the original object. If any of the fields of the object are references to other objects, just the references are copied. Thus, if the object you are copying contains references to yet other objects, a shallow copy refers to the same sub objects.
Deep copy is a complete duplicate copy of an object. If an object has references to other objects, complete new copies of those objects are also made. A deep copy generates a copy not only of the primitive values of the original object, but copies of all subobjects as well, all the way to the bottom. If you need a true, complete copy of the original object, then you will need to implement a full deep copy for the object.
Shallow -> One new copy of object + required number of references copied
Deep -> One new copy of object + required number of new copies of objects are made for references in parent object
Thanks & Regards,
Amarnath
Very Nice...
Deep Copy Sounds Peculiar..
Deep Copy : Does It Copy the Entire Tree Structure an Object has..???
What about the Object Names,Not Object reference Name ???Will they be same..???
class String
{
int size;
char* data;
};
String s1("Ace"); // 1