What is object deep copy and shallow copy?Deep copy:
- In deep copy the copy operations would respect the semantics of the object. - It copies all the fields and makes the copy of the dynamically allocated memory pointed to the field. - It occurs when an object is copied along with the objects to which it refers. - For example, copying an object along with the objects to which it refers to.
Shallow copy:
- A shallow copy copies an object without its contained objects. - It is a bitwise copy of an object. - The creation of a new object has the exact copy of the values in the original object. - Fields of any object are references of the other objects. - Only the reference address are copied i.e. the memory address is copied.
|