What is difference between above two. I understand both are same. (like, p2 = new p1; would in turn do p2 = new; p2 = p1;)
But it is not. In code 1, variable changed in p1 will be reflected in p2. But in code 2 variable changed in p1 would not change value in p2.
In this case, two handles, p1 and p2 will point to the same memory, so when we change any variable using handle p1, as the location is common, p2 will get the same value.
Case 2 (p2 = new p1):
This is an example of shallow copy. Here, p2 will create an exact copy of p1, so two different memories are created. Initially, both the objects have the properties with same values, but as the location are different, the change in a variable of p1 would not affect in a variable of p2.