Beruflich Dokumente
Kultur Dokumente
import java.util.Date;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
TestClone x1 = new TestClone();
TestClone x2;
x2 =(TestClone) x1.cloneTest();
System.out.println("x1: " + x1.a + " " + x1.b + x1.d);
System.out.println("x2: " + x2.a + " " + x2.b + x2.d);
x1.a=40;
x1.b=50;
x1.setdate();
System.out.println("x1: " + x1.a + " " + x1.b + x1.d);
System.out.println("x2: " + x2.a + " " + x2.b + x2.d);
}
}
/* output
* deep copy
* x1: 10 20.0Wed Jul 31 20:26:38 IST 2013
x2: 10 20.0Wed Jul 31 20:26:38 IST 2013
x1: 40 50.0Sat Jul 20 20:26:38 IST 2013
x2: 10 20.0Wed Jul 31 20:26:38 IST 2013
*/
/* shallow copy
* x1: 10 20.0Wed Jul 31 20:27:26 IST 2013
x2: 10 20.0Wed Jul 31 20:27:26 IST 2013
x1: 40 50.0Sat Jul 20 20:27:26 IST 2013
x2: 10 20.0Sat Jul 20 20:27:26 IST 2013
*/