wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes ?(cloning)  from a newbie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "?(cloning)  from a newbie" Watch "?(cloning)  from a newbie" New topic
Author

?(cloning) from a newbie

Panday Manako
Ranch Hand

Joined: Mar 29, 2001
Posts: 80
Hi!
What's the difference between cloning and assignment?
example:
int p[] = new int[10];
int p2[] = (int[])p.clone();
VS
int p[] = new int[10];
int p2[] = p;
Thanks in advance.

Siva Prasad
Ranch Hand

Joined: Feb 22, 2001
Posts: 104
in this case there is no difference. Its like copying the reference of one array to another.
Array Objects has their own overriden clone() method, which only does shallow copying. i.e. something like assinging the an array reference to another array reference variable.
Inorder to get your own clone behaviour, you need to write a public method clone() in your class which must call the protected clone() method inherited from Object method.
or you can implement the Cloneable interface.
Cheers
Siva
 
Don't get me started about those stupid light bulbs.
 
subject: ?(cloning) from a newbie
 
Similar Threads
sorting multidimensional arrays (int)
finding closest point
how modifier beheave second time ...
Static????????????
doubt in treeset...