What would happen if the House class (defined in Listing 1) did not override the clone() method or if House did not implement java.lang.Cloneable?
LISTING 1 House.java
1 public class House implements Cloneable, Comparable
{ 2 private int id;
3 private double area;
4 private java.util.Date whenBuilt;
5
6 public House(int id, double area) {
7 this.id = id;
8 this.area = area;
9 whenBuilt = new java.util.Date();
10 }
11
12 public int getId() {
13 return id;
14 }
15
16 public double getArea() {
17 return area;
18 }
19
20 public java.util.Date getWhenBuilt() {
21 return whenBuilt;
22 }
23
24 @Override /** Override the protected clone method defined in
25 the Object class, and strengthen its accessibility */
26 public Object clone() throws CloneNotSupportedException {
27 return super.clone();
28 }
29
30 @Override // Implement the compareTo method defined in Comparable
31 public int compareTo(House o) {
32 if (area > o.area)
33 return 1;
34 else if (area
35 return -1;
36 else
37 return 0;
38 }
39 }
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.