62,614
社区成员
发帖
与我相关
我的任务
分享
public class House implements Cloneable {
private java.util.Date whenBuilt;
private int id;
private double area;
public House(int id, double area, java.util.Date date) {
this.id = id;
this.area = area;
this.whenBuilt = date;
}
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
public static void main(String[] args) throws CloneNotSupportedException {
java.util.Date date = new java.util.Date();
House h1 = new House(1, 1750.50, date);
House h2 = (House)h1.clone();
System.out.println("h1 == h2 ? :" + (h1 == h2) );
System.out.println("h1 equals h2 ? :" + (h1.equals(h2)));
}
}