InterviewSolution
| 1. |
What Is The Fundamental Difference Between Shallow Copy And Deep Copy In Java? |
|
Answer» In Shallow copy a new object is created that has the same values like the original object. If any of the fields in the object reference other objects in that case only the memory ADDRESS is COPIED. In DEEP copy all fields are copied and copies are created for DYNAMICALLY allocated memory that points to by the fields. In deep copy, an object is copied along with the other objects it REFERS to. The default version of the clone () method will create a shallow copy of the object. In Shallow copy a new object is created that has the same values like the original object. If any of the fields in the object reference other objects in that case only the memory address is copied. In deep copy all fields are copied and copies are created for dynamically allocated memory that points to by the fields. In deep copy, an object is copied along with the other objects it refers to. The default version of the clone () method will create a shallow copy of the object. |
|