Interview Questions

clone() method is avail­able in Object class so can all objects of every class be cloned?

Java Interview Questions for Cloning and Cloneable


(Continued from previous question...)

clone() method is avail­able in Object class so can all objects of every class be cloned?

No, by default clone() method throws Clo­neNot­Sup­ported excep­tion when it is invoked on an object of a class not imple­ment­ing Clone­able inter­face. So to make the objects of a class clone­able, it should imple­ment the Clone­able interface.

(Continued on next question...)

Other Interview Questions