my dog learned polymorphism*
The moose likes Beginning Java and the fly likes clone Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "clone" Watch "clone" New topic
Author

clone

Rakesh Sharma
Ranch Hand

Joined: Dec 29, 2000
Posts: 37
what are clone objects and how it is useful?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Clone is not an object, it is a method for copying an object. Normally if you have a variable and it is "equal" to an object then the variable holds a reference to the location of the object.
Circle c1 = new Circle();
Circle c2 = new Circle();
c1 = c2;
Now you have 2 circles both containing the reference to a single object.
If you actually want to create a deep copy of the object (not just a copy of the reference), then you need to clone it.
c1 = c2.clone();
Now you have two object that are exactly ALIKE.


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
Consider Paul's rocket mass heater.
 
subject: clone