Consider the following inheritance example:
class A {...}
class B extends A
{
..
..
private static void main(String[] s)
{
A a1 = new A();
B b1 = new B();
B b2 = b1; // What if it was B b2 = new B(); b2 = b1;
}
}
My question is in the comment. Would it be different, in the sense that, using the new operator creates a new space for the object b2 and b2=b1 would just copy the data of b1 into b2. So any changes done to one object won't affect the other. In the main inline code, B b2 = b1 would point b2 to the space allocated for b1. So any changes here would affect both the object data.
My query is, will using the new operator make any difference to the object manipulation?