package day33;
public class d4 {
public static void main(String[] args)throws CloneNotSupportedException {
person p=new person("任我行",56);
person p2=(person)p.clone();
System.out.println("克隆前:"+p.getName()+","+p.getAge());
System.out.println("克隆后:"+p2.getName()+","+p2.getAge());
}
}
package day33;
public class person implements Cloneable{
private String name;
private int age;
public person(String name,int age)
{
this.name=name;
this.age=age;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name=name;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age=age;
}
@Override
protected Object clone() throws CloneNotSupportedException {
return super.clone();
}
}