Campbell Ritchie wrote:
mittal vishal wrote: . . . Final means reference cannot point to some other memory space, but the instance variable residing at that space can be changed.
That is confusing. What does it mean?
Every reference point to a memory space in heap. When any object is created, it is created on heap & the reference points to that memory space.
Step1) Object obj1 = new Object();
It means new objects is created on heap at some memory space. obj1 is pointing to that memory space
Now, if it is not declared as final then
Step2) Object obj2 = new Object();
Step3) obj1 =obj2; is a valid statement i.e. obj1 is now pointing to memory space where obj2 is pointing
but this is not a valid statement if obj1 was declared as final i.e. it is not allowed to point to some other memory space if it has already assigned a memory space.
In our case at step 1 it is pointing to a memory space so after that it cannot point to some other place