What is the difference between shallow copy and deep copy in Java?


When we copy an object, a shallow copy is where only the outer object is copied. For example, if we have an object named sample and it contains another object named subSample then if you copy this only the contents of the sample are copied.

When we copy an object deep copy is where whole object structure is copied i.e. if you copy sample the contents of both sample and subSample were copied.

Swarali Sree
Swarali Sree

I love thought experiments.

Updated on: 30-Jul-2019

175 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements