Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests - Download the BYJU'S Exam Prep App for free GATE/ESE preparation videos & tests -

Difference between Shallow and Deep copy of a Class

In Shallow copy, a copy of the original object is stored and only the reference address is finally copied. In Deep copy, the copy of the original object and the repetitive copies both are stored.

Ultimate Guide to Kickstart your GATE Exam Preparation
Download the e-book now

What is Shallow copy?

A bitwise copy of an object, where a new object is created and it has the same copy of the values in the original object, is called a Shallow copy. If any of the object fields refer to the other object then in such cases only the reference address is copied.

What is Deep copy?

When the process of copying occurs repetitively and a copy of the object is always copied in another object, then it is called deep copy. In this process, initially, a new collection of the object is constructed, and then the copies of the child object frequently populate those found in the original.

Difference between Shallow copy and Deep copy

S.No. Shallow Copy Deep Copy
1. In Shallow copy, a copy of the original object is stored and only the reference address is finally copied. In Deep copy, the copy of the original object and the repetitive copies both are stored.
2. Shallow copy is faster than Deep copy. Deep copy is slower than Shallow copy.
3. The changes made in the copied object also reflect the original object. There is no reflection on the original object when the changes are made in the copied object.
4. It stores references of the object in the main memory. It stores copies of the object values.

Keep learning and stay tuned to BYJU’S to get the latest updates on GATE Exam along with GATE Eligibility CriteriaGATE 2024GATE Admit CardGATE Application FormGATE SyllabusGATE CutoffGATE Previous Year Question Paper, and more.

Comments

Leave a Comment

Your Mobile number and Email id will not be published.

*

*