class TestClone implements Cloneable {
int a;
double b;
TestClone cloneTest() {
try {
return (TestClone) super.clone();
}
catch(CloneNotSupportedException e) {
System.out.println("Cloning not allowed.");
return this;
}
}
}
class CloneDemo {
public static void main(String args[]) {
TestClone x1=new TestClone();
TestClone x2;
x1.a=10;
x1.b=20.67;
x2=x1.cloneTest();
System.out.println("x1: "+x1.a+" "+x1.b);
System.out.println("x2: "+x2.a+" "+x2.b);
}
}这里的super.clone()的意义,(TestClone)对上面所作的改变
int a;
double b;
TestClone cloneTest() {
try {
return (TestClone) super.clone();
}
catch(CloneNotSupportedException e) {
System.out.println("Cloning not allowed.");
return this;
}
}
}
class CloneDemo {
public static void main(String args[]) {
TestClone x1=new TestClone();
TestClone x2;
x1.a=10;
x1.b=20.67;
x2=x1.cloneTest();
System.out.println("x1: "+x1.a+" "+x1.b);
System.out.println("x2: "+x2.a+" "+x2.b);
}
}这里的super.clone()的意义,(TestClone)对上面所作的改变
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货