0% found this document useful (0 votes)
9 views7 pages

Shallo and Deep Capy

The document explains the differences between shallow copy and deep copy in programming. Shallow copy creates a new reference to the same object, while deep copy creates a new object with the same data but a different identity. The deep copy process involves using a clone method that requires explicit casting to obtain the desired type.

Uploaded by

mariiam.hesham29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views7 pages

Shallo and Deep Capy

The document explains the differences between shallow copy and deep copy in programming. Shallow copy creates a new reference to the same object, while deep copy creates a new object with the same data but a different identity. The deep copy process involves using a clone method that requires explicit casting to obtain the desired type.

Uploaded by

mariiam.hesham29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Shallow Copy Vs.

Deep Copy
Depend on Reference Type

by Arwa Alaa
Object Hint

Object Contain Two Parts :

1. Identity >> Address At Stack

2. State >> Data At Heap


by Arwa Alaa
Shallow Copy and Deep Copy

Shallow Copy is take copy from reference(address of object)


(from stack)

Deep Copy is Copy state (data)of Object (from heap)

by Arwa Alaa
Shallow Copy

Now , Arr2 contain address of Arr1 and refer to object of Arr1


That mean two references Arr1 ,Arr2 refer to same object now

by Arwa Alaa
Deep Copy

Deep Copy is Copy state of Object (data)

Deep Copy use Clone Method that return object so we need make
explicit casting to get type needed .

Clone method will generate new object in heap with new and
different Identity but with the same object state (data) of caller object

by Arwa Alaa
Deep Copy

Deep Copy Use Clone Arr2 Identity Changed And Take state(data)
Method from Arr1 in new created object at heap

We make Explicit casting as


the return type of Clone method
is object we need type Int[]
by Arwa Alaa
Stay Tuned for Ways to Implement Deep Copy Next Post ☺.

by Arwa Alaa

You might also like