Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Cloning v/s Reference Copying  RSS feed

 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sir...

I hav a doubt regarding cloning v/s refernce copying.
If u clone any object by java's clone method. It gives u copy of original object.
Say i hav simple code.

Clone Test c1=new CloneTest();
CloneTest c2=(Object)c1.clone(); // gets the clone of newly created object.

System.out.println("Original object " + c1 + " Cloned object " + c2);

here c1 and c2 both display same address. It means c1 and c2 are pointing to same object. Same behaviour u can get by jst reference copying like this.

CloneTest c1=new CloneTest(), c2;
c2=c1; //c1 and c2 prints same address after this line

so wat the difference between the two and wat is the power of cloning? I know its shallow copying.

plz help me!!!

Thanks and Regards

Naseem khan
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Crossposted here
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!