class student implements Cloneable
{
String name;
int age;
student(String name,int age)
{
this.name = name;
this.age = age;
}
public Object clone()
{
Object o = null;
try
{
o = super.clone();
}
catch(CloneNotSupportedException e )
{
System.out.println(e.toString());
}
return o;
}
}
public class clone {
public static void main(String []str)
{
student s1 = new student("weiwei",28);
student s2 = (student)s1.clone();
s2.name = "lili";
s2.age = 29;
System.out.println("name="+s1.name+",age="+s1.age);
System.out.println("name="+s2.name+",age="+s2.age);
}
}