aspose file tools*
The moose likes Beginning Java and the fly likes Using final Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Using final " Watch "Using final " New topic
Author

Using final

r suraaj
Greenhorn

Joined: Oct 26, 2008
Posts: 16
Hi.,
my doubt is about final keyword.,

i think a variable whether it is primitive or reference variable ., when it is declared as final variable we can't modify that value.,

but can we assign a final reference variable of an object to another reference variable of the same class?
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

Final in combination with a primitive means that it's value can never change.
Final in combination with a reference means that the reference can never change.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
W. Joe Smith
Ranch Hand

Joined: Feb 10, 2009
Posts: 710
r suraaj wrote:Hi.,
my doubt is about final keyword.,

i think a variable whether it is primitive or reference variable ., when it is declared as final variable we can't modify that value.,

but can we assign a final reference variable of an object to another reference variable of the same class?


It depends.

You can do something like this:



But you can't do this:



Once the reference variable is assinged an object, the reference cannot be changed. Note that the object state can change, such as below:



SCJA
When I die, I want people to look at me and say "Yeah, he might have been crazy, but that was one zarkin frood that knew where his towel was."
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Using final