Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (6.5k points)
edited by
Could someone tell me what is object cloning?

1 Answer

0 votes
by (11.3k points)

By using object cloning in JAVA, we can create an exact copy of an object. We use the clone() method for this. To implement this, we must need to use the interface, java.lang.Cloneable interface. in the class which we are instantiating. If we do not implement the Cloneable interface in the class, then, upon calling the clone() function, a CloneNotSupportedException is encountered. 

The following is the syntax of the function:

protected Object clone() throws CloneNotSupportedException

This can very useful to avoid declaring an object again to create a copy of the method or to create a copy of an instance in a particular state way after its declaration. 

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...