Wednesday, April 18, 2007

Can you change the reference of the final object?

No the reference cannot be changed, but the data in that object can be changed.


Anonymous said...

Can you give us an example

Anonymous said...

Yes ! For eg.

final SomeClass objReference = new SomeClass();

objReference -> final reference;
new SomeClass() -> Object on heap;

now pointing the reference to some other new Object on heap.

objReference = new SomeClass("anothet object ");

which is not correct ie wrong.

But on other hand we can modify the object which is pointed by objReference ie new SomeClass();

eg objReference.modifyMe(); which modifies the object not the reference !


Interview Questions On Java,Java EE Copyright © 2016. Reads: best tracker