Get Started
817

Q: What is Shallow and deep cloning in Java?

  • Show Answer
  • Workspace

Answer :
Explanation :

Cloning refers to creating duplicate copies of objects in java. Shallow Cloning: Shallow cloning is a bitwise copy of an object. New object is created which is an exact copy that of the original one. In case any objects are referring the fields of these objects, just the references are copied. Deep Cloning: In deep cloning, complete duplicate copy of the original copy is created. Deep cloning creates not only the primitive values of the original objects but also copies all its sub objects as well. Clonable interface is used to perform cloning in java.

The Most Comprehensive Exam Preparation Platform

Get the Examsbook Prep App Today