You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* In the deep copy, we create a clone which is independent of original object and making changes in the cloned object should not affect original object.
* So for deep copy we need to ensure all the member class also implement the Cloneable interface and override the clone() method of the object class.
*/
import java.util.ArrayList;
class DeepCopy1 {
int x, y;
}
class DeepCopy2 implements Cloneable {
int a, b;
DeepCopy1 c = new DeepCopy1();
public Object clone() throws CloneNotSupportedException {
DeepCopy2 t = (DeepCopy2)super.clone();
t.c = new DeepCopy1();
return t;
}
}
public class DeepCopy {
public static void main(String[] args) throws CloneNotSupportedException {