import java.util.*; class Day { private int year, month, day; public Day(int y, int m, int d) {year=y; month=m; day=d; } public int getYear() {return year;} public int getMonth() {return month;} public int getDay() {return day;} public void setDay(int y, int m, int d) {year=y; month=m; day=d; } @Override public String toString() { final String[] MonthNames = { "Jan", "Feb", "Mar", "Apr","May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; return day+" "+ MonthNames[month-1] + " "+ year; } } class Employee implements Cloneable { private String name; private double salary; private Day hireDay; public Employee(String n, double s, int year, int month, int day) { name = n; salary = s; hireDay = new Day(year,month,day); } void setName(String n) {name=n;} void setSalary(double s) {salary=s;} void setHireDay(Day d) {hireDay=d;} Day getHireDay() {return hireDay;} @Override public String toString() { return "name=" + name + ",salary=" + salary +",hireDay=" + hireDay; } @Override public Employee clone() throws CloneNotSupportedException { Employee copy = (Employee) super.clone(); // actually by the superclass Object copy.hireDay = new Day(this.hireDay.getYear(), this.hireDay.getMonth(), this.hireDay.getDay()); // Or call // .clone of // this.hireDay copy.name = new String(this.name); // Can be omitted, since strings are immutable return copy; } } public class Main { public static void main(String[] args) throws CloneNotSupportedException { Employee e = new Employee("Carl Cracker", 75000, 1987, 12, 15); Employee e2 = e; Employee e3 = e.clone(); e.getHireDay().setDay(1988, 1, 1); e.setName("Helena"); e.setSalary(88000); System.out.println(e); System.out.println(e2); System.out.println(e3); } }