Possible Duplicate:
Clone() vs Copy constructor- which is recommended in java
In below example,is there any difference between the objects created by useClone
and copyConstrutor
?
class A implements Cloneable{
int data = 9;
public A useClone() throws CloneNotSupportedException {
return (A)super.clone();
}
public A copyConstrutor() {
A o = new A();
o.data = this.data;
return o;
}
}