Shallow Copy Deep Copy Java example
Shallow Copy Deep Copy Java example Before knowing about Shallow Copy and Deep Copy you need to know about Clonable interface. Clonable interface - Java has a clonable interface for make clone of any object. Clonable Interface is a marker interface. Clonable Interface has no method. Class which implements Clonable interface, JVM give the permission for making the clone of this class. Shallow Copy - Clone can be archived by object.clone() method. It gives the Shallow copy of the object. In this process a new object is created That have all the value and instance variable. And if main object has any references to other object then the references are copied in the shallow copy. Example - class A implements Cloneable{ A(String personName, Integer age){ ...