This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Java in General and the fly likes Query with Cloning of an Object Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Query with Cloning of an Object" Watch "Query with Cloning of an Object" New topic
Author

Query with Cloning of an Object

PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
ShallowCloning : A new Object is created , but its variables refer to the same location and the default Object clone method only returns a shallow copy of an Object .



But this gives me (pav1.a) gives me only the value 10 (even though i chnaged to 20 with pav2.a=20)

why the value of a is not copied .


Any ideas ??
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



int are primitive types and are not obejcts so they dont live in heap. Clone will just copy the value of int and create a new int. Any changes to primitive types will not be reflected.
PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
Great Balu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Query with Cloning of an Object