public class Student implements Cloneable
{
private String name;
private int age;
Student(String name, int age)
{
this.name = name;
this.age = age;
}
@Override
public Object clone() throws CloneNotSupportedException
{
return super.clone();
}
public static void main(String[] args) throws CloneNotSupportedException
{
Student s1 = new Student("zhangsan", 18);
Student s2 = (Student) s1.clone();
s2.name = "lisi";
s2.age = 14;
System.out.println(s1.name + " " + s1.age);
System.out.println(s2.name + " " + s2.age);
System.out.println(s1.name == s2.name);
}
}