GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 452 of 502    Print  
What is Shallow cloning in Java ?

  
Total Answers and Comments: 5 Last Update: February 11, 2009     Asked by: fred 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: nareshv1
 
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.

Above answer was rated as good by the following members:
Naveenjavasun, talktoatish
November 30, 2007 03:22:24   #1  
tryingtobejavageek Member Since: November 2007   Contribution: 1    

RE: What is Shallow cloning in Java ?
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.
 
Is this answer useful? Yes | No
February 14, 2008 00:57:27   #2  
sampra Member Since: February 2008   Contribution: 278    

RE: What is Shallow cloning in Java ?
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.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
June 13, 2008 02:24:17   #3  
nareshv1 Member Since: June 2008   Contribution: 2    

RE: What is Shallow cloning in Java ?
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.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 08, 2008 04:02:55   #4  
Naveenjavasun Member Since: July 2008   Contribution: 6    

RE: What is Shallow cloning in Java ?
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.

 
Is this answer useful? Yes | No
February 11, 2009 00:33:37   #5  
TypeEE Member Since: February 2009   Contribution: 1    

RE: What is Shallow cloning in Java ?
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.


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape