ProAnswers.org

Differentiate between a deep copy and a shallow copy?

Differentiate between a deep copy and a shallow copy?

	[b]Deep Copy: [/b]Copies the member values from one object into another. Any pointer objects are duplicated and Deep Copied.Deep copy literally performs a deep copy. It means, that if your class has some fields that are references, their values will be copied, not references themselves.



	If, for example you have two instances of a class, A & B with fields of reference type, and perform a deep copy, changing a value of that field in A won't affect a value in B. And vise-versa. Things are different with shallow copy.



	[b]Shallow copy: [/b] In Shallow copy only references are copied, therefore, changing this field in a copied object would affect the original object.