What is Shallow cloning in Java ?

Showing Answers 1 - 15 of 15 Answers

sampra

  • Feb 14th, 2008
 

Shallow cloning is a way to create a replica of object where object copy is created but the objects that are contained in that object are not copied.

nareshv1

  • Jun 13th, 2008
 

When we need a copy of the object we go for cloning.
When an object is shallow coned the parent object or top level object and its members are duplicated, where as the low level objects are not duplicated but their references are alone copied.

When we need a copy of the object we go for cloning. When an object is shallow coned the parent object or top level object and its members are duplicated, where as the low level objects are not duplicated but their references are alone copied.

For complete cloning go for deep cloning
Deepcloing is done in two ways 1,serilization and 2,cloning all related objects.

  Was this answer useful?  Yes

TypeEE

  • Feb 11th, 2009
 

By default, cloning yields a shallow copy. By shallow, we mean the object is copied, but the contained objects are not. What a deep copy does it copy the cloned object, as well as all the objects within.

For instance, if you have an array of five elements, you have a total of six objects in memory, the array and the five elements. If you make a shallow copy, you have a total of seven objects in memory: the original array, the copied array, and the set of five elemenets that both arrays contain. For a deep copy, there would be a total of twelve elements since the five elements inside the array will be copied, too. Of course, if each of those elements contained even more objects, then the resulting set of objects would grow even larger.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions