//If we do not add "implements Cloneable", then runtime exception: java.lang.CloneNotSupportedException public class Employee implements Comparable, 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 int compareTo(Employee another) { if (this.salary == another.salary) return 0; else if (this.salary > another.salary) return 1; else return -1; } @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; } }