Posted in Java

Copy Constructor in Java

What is Copy Constructor? Sometimes a programmer wants to create an exact but separate copy of an existing object so that subsequent changes to the copy should not alter the original or vice versa. This is made possible using the copy constructor. A copy constructor is a constructor that creates a new object using an existing object of the same…

Continue Reading... Copy Constructor in Java
Posted in Java

Shallow Copy And Deep Copy In Java

Shallow Copy/Deep Copy Shallow Copy also means Shallow Clone and Deep Copy also means Deep Clone. Cloning an object is about creating the copy of the original object, i.e., making an identical copy of the original object. By default, cloning in Java is field by field copy i.e. as the Object class does not have idea about the structure of…

Continue Reading... Shallow Copy And Deep Copy In Java