Wednesday, April 18, 2007
Can you change the reference of the final object?
Subscribe to:
Post Comments (Atom)
World of tricky Core Java Q&A(Java SE),Java EE and Open source technologies like Struts,Hibernate,Spring,Velocity etc
Disclaimer
Interview Questions On Java,Java EE Copyright © 2012
2 comments:
Can you give us an example
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 !
Post a Comment