211.深复制(复制对象和其应用对象)

深拷贝不仅复制对象本身,而且复制对象包含的引用指向的所有对象。

class Student implements Cloneable {
 String name;
 int age;
 Professor p;
 Student(String name, int age, Professor p) {
 this.name = name;
 this.age = age;
 this.p = p;
 }
 public Object clone() {
 Student o = null;
 try {
 o = (Student) super.clone();
 } catch (CloneNotSupportedException e) {
 System.out.println(e.toString());
 }
 o.p = (Professor) p.clone();
 return o;
 }
}