62,623
社区成员
发帖
与我相关
我的任务
分享
import java.sql.Connection;
import java.sql.DriverManager;
class Student implements Cloneable {
int age;
String name;
Professor p;
Student(int age, String name, Professor p) {
this.name = name;
this.age = age;
this.p = p;
}
public Object clone() {
Object o = null;
try {
o = super.clone();
} catch (CloneNotSupportedException e) {
System.out.println(e.toString());
}
return o;
}
}
class Professor implements Cloneable {
int age;
String name;
Professor(int age, String name) {
this.name = name;
this.age = age;
}
public Object clone() {
Object o = null;
try {
o = super.clone();
} catch (Exception e) {
System.out.println(e.toString());
}
return o;
}
}
public class Test {
public static void main(String[] args) {
Professor p = new Professor(44, "ccc");
Student s1 = new Student(22, "aaa", p);
System.out.println(s1.p.name);
}
}
public class Test {
public static void main(String[] args) {
Professor p = new Professor(44, "ccc");
Student s1 = new Student(22, "aaa", p);
System.out.println(s1.p.name);
}
}