Originally posted by dolly shah:
This code is from chapter-3, K & B book,page:262.
It is describe in the answer that "the references f1,z & f3 all refer to the same instance of Fizz. AS I understand they are talking about variable x. Please correct me if I am wrong.
They also describe.
"The final modifier assures that a reference variable cannot be referred to a different object, but final doesn't keep the object's state from changing."
What they want to say by this description? How it is related to this question?
In short I don't understand this example at all. Can anyone please help me?
looks to me that:
System.out.println((f1==f3
f1==f3 is boolean, so there's no assignment. i think all this code is legal.
z.x=6 is updating an instance variable, not changing z's reference to another object, which would be illegal since z is final.
"The final modifier assures that a reference variable cannot be referred to a different object, but final doesn't keep the object's state from changing."
so that says when the first Fizz object (f1) is createdm, its instance variable (x) is 5. later, antoher Fizz object is created and it changes x to 6. so the quotes are saying you can change the instance variable of an objects state, just not change the objects reference to refer to a new object because it's final.
than's what i think... i'm studying as you are.