1 类实现Cloneable接口
2 重写clone()方法
3 类变量引用类型无法复制
class Dog extends Pet implements Cloneable{
int c;
int d;
public Dog clone() {
Dog clone=null;
try {
clone=(Dog) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return clone;
}
}