Java????????(Prototype)
???????????? ???????[ 2014/3/21 11:03:05 ] ????????Java ??? ???
????1??????
?????????(Prototype)??????????????????????????????μ????????????????????????????????????????????????????????????????
????2?????
?????????????????????????????????????????????????????????????????????????Щ???????μ????
????3???????UML?
????4?????
????1>?????????????????
????2>??????????????????????????
????3>????????????
????5?????????
??????1??????Java?е?clone???????????????
???????????
public class Professor {
private String address;
private double salary;
public Professor(String address?? double salary) {
this.address = address;
this.salary = salary;
}
public void setAddress(String address) {
this.address = address;
}
public void setSalary(double salary) {
this.salary = salary;
}
@Override
public String toString() {
return "Professor [address=" + address + "?? salary=" + salary + "]";
}
}
public class Student implements Cloneable {
private String name;
private int age;
private Professor professor;
public Student(String name?? int age?? Professor professor) {
this.name = name;
this.age = age;
this.professor = professor;
}
@Override
public String toString() {
return "Student [name=" + name + "?? age=" + age + "?? Professor="
+ professor.toString() + "]";
}
@Override
public Object clone() {
Student student = null;
try {
// ?????????Object?е?clone???????????????????????Object?е?clone()
// ???????????????????ж??????????????????????????????????洢????С?
student = (Student) super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return student;
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11