Person p1 = new Person();
Person p2 = p1;
what will happen and how the memory is allocated?
Person p1 = new Person();
Person p2 = p1;
what will happen and how the memory is allocated?
Hi Siddharth,
Person p1 = new Person();
When you use the new keyboard, it means you want to create a new object and allocate some amount memory to the object you are creating.
Person p2 = p1;
Whereas here, you are creating a reference object. The reference object is like a pointer. This did not create an object, but it just linked its pointed to object p1.
Hope this clears your doubt.