clone() is a method in the Java programming language for object duplication. Since objects in Java are manipulated through reference variables, there is no direct way to copy an object. (We would be trying to duplicate the reference variable rather than the object control referred to through that variable).
Classes that want copying functionality must implement some method to do so. To a certain extent that function is provided by "clone()".
clon...
more
clone() is a method in the Java programming language for object duplication. Since objects in Java are manipulated through reference variables, there is no direct way to copy an object. (We would be trying to duplicate the reference variable rather than the object control referred to through that variable).
Classes that want copying functionality must implement some method to do so. To a certain extent that function is provided by "clone()".
clone() acts like a constructor. Typically it calls the clone() method of its superclass to obtain the copy, etc. until it eventually reaches Object's clone() method. The special clone() method in the base class Object provides a standard mechanism for duplicating objects.
The class Object's clone() method creates and returns a copy of the object, with the same class and with all the fields having the same values. However, clone() throws a CloneNotSupportedException unless the class you are trying to use it on implements the marker interface...
less