Java Clone Example
Chapter:
Java Basics
Last Updated:
02-05-2016 19:10:35 UTC
Program:
/* ............... START ............... */
import java.util.GregorianCalendar;
public class JavaCloneExample {
public static void main(String[] args) {
// create a gregorian calendar
GregorianCalendar calendar1 = new GregorianCalendar();
// clone object calendar1 into object calendar2
GregorianCalendar calendar2 = (GregorianCalendar) calendar1.clone();
System.out.println("" + calendar1.getTime());
System.out.println("" + calendar2.getTime());
}
}
/* ............... END ............... */
Output
Mon May 02 22:34:44 GST 2016
Mon May 02 22:34:44 GST 2016
Notes:
-
The clone() method saves the extra processing task for creating the exact copy of an object.
Tags
Clone Example, Java , Java Basics