Object Cloning in Java
A is an exact copy of the original. The clone() method provides this functionality.
The java.lang.Cloneable interface must be implemented by the class whose clone object wants to create. If Cloneable interface is not implemented, clone() method generates CloneNotSupportedException.
Facts about cloning
i.e. as the class does not have idea about the structure of class on which method will be invoked. So, JVM when called for cloning, do following things:
1) If the class has then a completely new copy of the object will be created and the reference to the .
2) If the class contains then only the object references to those members are copied and hence the .
Facts behind cloning
1) You must implement interface.
2) You must override method from Object class. ]