All stories
Java

Shallow Copy vs Deep Copy

H
hemant-kumar

September 5, 2012

Shallow Cloning (Shallow Copy)

In Shallow copy all the fields are just copied from source object to destination object.

If the source object is containing any field that holds a reference to another object then only the reference will be copied i.e. source and destination objects field(that particular field) will point to same memory location.

Deep Cloning (Deep copy)

In Deep copy all the fields are deeply copied from source object to destination object.

If the source object is containing any field that holds a reference to another object then for the destination object a new copy will be created i.e. source and destination objects field will point to different memory location.

Java

0

If you found this helpful, give it some claps!

SHARE THIS ARTICLE

Share on X
LinkedIn

Responses0

Sign in to join the conversation

Sign in