Interview Questions

How does one create object clones?

Java Interview Questions for Cloning and Cloneable


(Continued from previous question...)

How does one create object clones?

One can create object clones by invoking the clone method on the object to be cloned. The clone() method is defined as protected method in the Object class and is thus inherited by all the classes.
The only requirement for creating object clones is that the class whose objects are being cloned should implement the Cloneable interface. If this is not done that a CloneNotSupported Exception is thrown on calling the clone method.

(Continued on next question...)

Other Interview Questions