File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes final reference variable doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic

final reference variable doubt

saloni jhanwar
Ranch Hand

Joined: Feb 09, 2012
Posts: 583

BOOK-->>K&B 6
Final Variables
Declaring a variable with the final keyword makes it impossible to reinitialize that variable once it has been initialized with an explicit value (notice we said explicit rather than default). For primitives, this means that once the variable is assigned a value, the value can't be altered. For example, if you assign 10 to the int variable x, then x is going to stay 10, forever. So that's straightforward for primitives, but what does it mean to have a final object reference variable? A reference variable marked final can't ever be reassigned to refer to a different object. The data within the object can be modified, but the reference variable cannot be changed. In other words, a final reference still allows you to modify the state of the object it refers to, but you can't modify the reference variable to make it refer to a different object. Burn this in: there are no final objects, only final references. We'll explain this in more detail in Chapter 3.

I want know that how data of that object can modify.

like final Integer i=new Integer(5);

how data of this object can be modify ?

Tell the difficulties that i am difficult.
Jaikiran Pai

Joined: Jul 20, 2005
Posts: 10441

Here's an example which might help you understand what that statement means:

[My Blog] [JavaRanch Journal]
Matthew Brown

Joined: Apr 06, 2010
Posts: 4544

This is a (probably accidental) duplicate of I'll lock this thread, so any further discussion can take place back there.
subject: final reference variable doubt
It's not a secret anymore!