被克隆的对象所属的类:
实现 Cloneable 接口
继承Object的clone()方法
public class Person implements Cloneable{
private String name;
private int age;
protected Object clone() throws CloneNotSupportedException{
return super.clone();
}
}
创建克隆对象
Person a = new Person("小明",10);
Person p = (Person) a.clone();
System.out.println(p); //Person(name=小明, age=10)