Interview Questions

What is cloning and when to use it?

Java Interview Questions for Cloning and Cloneable


(Continued from previous question...)

What is cloning and when to use it?

Cloning is the process of creating one more copy of an object. Cloning should be used when we want to create multiple objects of a class with same state as the source object. Basically when we clone an object, we avoid invoking any initialization code and other method calls on the source object.

clone() is a method in the Java programming language for object duplication. In Java, objects are manipulated through reference variables, and there is no operator for copying an object the assignment operator duplicates the reference, not the object.

(Continued on next question...)

Other Interview Questions