当前位置: 代码迷 >> Java相关 >> [求助]克隆的程序题
  详细解决方案

[求助]克隆的程序题

热度:221   发布时间:2007-07-11 17:29:01.0
[求助]克隆的程序题
编写一个类实现浅克隆,该类的成员变量至少有一个基本类型,一个引用类型,在另外一个类中对上类的克隆方法进行测试。
帮下忙,谢了
搜索更多相关的解决方案: 克隆  

----------------解决方案--------------------------------------------------------

package clone;

public class Test implements Cloneable {
int i=0;
String s="Test";
public Object clone()throws CloneNotSupportedException{
return super.clone();
}

public static void main(String[] args)throws CloneNotSupportedException{
Test t=new Test();
Test a=(Test)t.clone();
System.out.println(t.i+t.s);
System.out.println(a.i+a.s);
}
}


----------------解决方案--------------------------------------------------------
  相关解决方案