package liu.prototype.demo;
public class WorkExperience {
private String workDate;
private String company;
public void setWorkDate(String workDate) {
this.workDate = workDate;
}
public String getWorkDate() {
return workDate;
}
public void setCompany(String company) {
this.company = company;
}
public String getCompany() {
return company;
}
}
private String company;
public void setWorkDate(String workDate) {
this.workDate = workDate;
}
public String getWorkDate() {
return workDate;
}
public void setCompany(String company) {
this.company = company;
}
public String getCompany() {
return company;
}
}
----------------------------------------
package liu.prototype.demo;
public class Resume implements Cloneable {
private String name ;
private String sex;
private String age;
private WorkExperience work;
public Resume(String name){
this.name = name;
work = new WorkExperience();
}
public void setPersonalInfo(String sex, String age){
this.age = age;
this.sex = sex;
}
public void setWorkExperience(String workDate, String company){
work.setCompany(company);
work.setWorkDate(workDate);
}
public void display(){
System.out.println("姓名:"+name);
System.out.println("年龄:"+age);
System.out.println("性别:"+sex);
System.out.println("工作时间:"+work.getWorkDate());
System.out.println("公司:"+work.getCompany());
}
public Object clone(){
Object object = null;
try {
object = super.clone();
} catch (CloneNotSupportedException e) {
System.err.println("AbstractSpoon is not Cloneable");
e.printStackTrace();
}
return object;
}
}
----------------------------------------
package liu.prototype.demo;
private String sex;
private String age;
private WorkExperience work;
public Resume(String name){
this.name = name;
work = new WorkExperience();
}
public void setPersonalInfo(String sex, String age){
this.age = age;
this.sex = sex;
}
public void setWorkExperience(String workDate, String company){
work.setCompany(company);
work.setWorkDate(workDate);
}
public void display(){
System.out.println("姓名:"+name);
System.out.println("年龄:"+age);
System.out.println("性别:"+sex);
System.out.println("工作时间:"+work.getWorkDate());
System.out.println("公司:"+work.getCompany());
}
public Object clone(){
Object object = null;
try {
object = super.clone();
} catch (CloneNotSupportedException e) {
System.err.println("AbstractSpoon is not Cloneable");
e.printStackTrace();
}
return object;
}
}
----------------------------------------
package liu.prototype.demo;
public class Main {
public static void main(String[] args) {
Resume a = new Resume("大鸟");
a.setPersonalInfo("male", "29");
a.setWorkExperience("2009", "xx company");
Resume b = (Resume)a.clone();
b.setWorkExperience("2009", "yy company");
Resume c = (Resume) a.clone();
c.setPersonalInfo("male", "24");
c.setWorkExperience("2008", "zz company");
a.display();
b.display();
c.display();
}
c.setPersonalInfo("male", "24");
c.setWorkExperience("2008", "zz company");
a.display();
b.display();
c.display();
}
}
----------------------------------------
----------------------------------------
----------------------------------------
----------------------------------------