import java.util.*; //有关clone与equals方法的应用
public class CloneEqual { public static void main(String[] args) { Date d1,d2,d3; d1 = new Date();
d2 = d1;//执行内存中相同的对象
d3 = (Date)d1.clone();//clone方法返回的是Object类型,需要强制转换为Date
System.out.println("d2=d1的结果:true???"+(d2==d1)); System.out.println("d2.equals(d1)的结果:true???"+(d2.equals(d1))); System.out.println("d3=d1的结果:false???"+(d3==d1)); System.out.println("d3.equals(d1)的结果:true???"+(d3.equals(d1)));
System.out.println("d1 :"+d1); System.out.println("d2 :"+d2); System.out.println("d3 :"+d3); } }