Modified Code:
Now the output is true true.
can any one please explain me the line 6,7,9 and 11
Line 6: You are calling a static method FizzSwitch() passing f1 and f2 to it.
Line 9: Nothing special here, simple static method signature. If you are
getting confused with final parameter, no problem, make then both final,
it will be accepted but inside the method you can't dereference them.
Line 10: Another reference variable z of type Fizz is created that is final,
means can't be dereferenced once referenced. You set its reference to the x,
that is f1 in main;
Line 11: You set the value of x to 6 hence references can be final, objects
can't be. You can change the internal state of an object as you did by changing the value of x to 6.
You returned the z;
Line 7: Now what is returned from FizzSwitch() method, you assigned to f3.
Now you know f3 and f1 are referring to same object on the heap.
They are == (referring to same object) and their value x is ==.
Regards,
cmbhatt