How to clone objects

This example shows how to clone objects by implementing the Cloneable interface. Some classes implements the Cloneable interface by default but when creating custom classes the interface needs to be implemented explicitly.
The class that implements the Cloneable interface (the Person class in the example) needs to have a method named clone() that returns an object.
In the example we have chosen to create a new instance of Person and populate its properties with the same values as the object that the clone() method
is called on.

Since we chose to populate the cloned object with the same values of its variables as the object that the clone() method was call on, the output of the above example will look like this:

Search for more Java info on this site here:
Custom Search

Please type any questions here.