public class Student implements Cloneable {
String name;
int age;
Student(String name, int age) {
this.name = name;
this.age = age;
}
void print() {
System.out.println("学生信息:");
System.out.println(this.name + "\t" + this.age);
}
public Student clone() {
Student stu = null;
try { stu = (Student) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return stu;
}
}
class TestProto {
public static void main(String args[]) throws Exception {
Student s1 = new Student("Tom",19);
s1.print();
Student s2 = s1.clone();
s2.print();
System.out.println(s1 == s2);
System.out.println(s1.name == s2.name);
}
}