Consider the following code snippet in Java:
Customer obj1 = new Customer();
Customer obj2 = new Customer();
Customer obj3 = obj2;
obj3 = obj1;
How many reference variables and objects are created here?
The solutions I came across were all confusing. Please explain.
// Customer object is created on the heap and obj1 refers it
//Customer object is created on the heap and obj2 refers it
// obj3 will refer to customer object created by obj2
// obj3 (previosly refering to cust obj craeted by obj2 will be lost) and will now refer to cust obj created by obj1
Thus i would say 2 objects and 3 ref variables