浅克隆
package fun;
public class b extends a implements Cloneable {
public static void main(String[] args) throws CloneNotSupportedException {
b b=new b();
b b1=(fun.b) b.clone();//调用clone的方法,返回Object类,需要强转
b1.fun();
b.fun();
}private void fun() {
System.out.println("123");
}
@Override//复写clone的方法
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
原文:http://www.cnblogs.com/joyous-day/p/6490963.html