工作经验类
public class WorkExperience implements Cloneable {private String workDate;private String company;public void setWorkDate(String workDate) {this.workDate = workDate;}public void setCompany(String company) {this.company = company;}@Overridepublic Object clone() throws CloneNotSupportedException {WorkExperience obj = new WorkExperience();obj.workDate = this.workDate;obj.company = this.company;return obj;}@Overridepublic String toString() {return "WorkExperience{" +"workDate='" + workDate + '\'' +", company='" + company + '\'' +'}';}
}
简历类
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();}private Resume(WorkExperience work) throws CloneNotSupportedException {this.work = (WorkExperience) work.clone();}public void setPersonInfo(String sex, String age) {this.sex = sex;this.age = age;}public void setWorkExperience(String workDate, String company) {work.setWorkDate(workDate);work.setCompany(company);}@Overridepublic Object clone() throws CloneNotSupportedException {Resume obj = new Resume(this.work);obj.name = name;obj.sex = sex;obj.age = age;return obj;}@Overridepublic String toString() {return "Resume{" +"name='" + name + '\'' +", sex='" + sex + '\'' +", age='" + age + '\'' +", work=" + work +'}';}
}
演示类
public class WorkResume {public static void main(String[] args) throws CloneNotSupportedException {Resume a = new Resume("张三");a.setPersonInfo("男","29");a.setWorkExperience("1998~2000","XXX公司");System.out.println(a);Resume b= (Resume) a.clone();b.setWorkExperience("2001~2006","YYY公司");System.out.println(b);}
}
演示结果