Can you give me an example. I always thought that final means dead end. I mean that is it! It can not be changed as long as the scope of the varibale remains. When the scope dies, the GC might come in and destroy the variable. Now I know that it can be manipulated. I learn better with siimple small code.. PleasE?

Working on my SCWCD so I can be a J2EE consultant earning millions of dollars and showing everyone I can

Ankur Jain Kothari

Ranch Hand

Posts: 154

posted 6 years ago

what page did you find this?

Do What You Wanna Be....Taking Things The Way They Come
scjp 1.6 91 percent, scmad 90 percent(rounded off to nearest integer)

Swagato Bhatta

Ranch Hand

Posts: 72

posted 6 years ago

Ankur Jain Kothari wrote:what page did you find this?

page 202... of 1st edition!

Working on my SCWCD so I can be a J2EE consultant earning millions of dollars and showing everyone I can

Ankur Jain Kothari

Ranch Hand

Posts: 154

posted 6 years ago

then which topic?i have 2nd edition

Do What You Wanna Be....Taking Things The Way They Come
scjp 1.6 91 percent, scmad 90 percent(rounded off to nearest integer)

Swagato Bhatta

Ranch Hand

Posts: 72

posted 6 years ago

Ankur Jain Kothari wrote:then which topic?i have 2nd edition

in 2nd edition it is on page 204....

final are not final.jpg

Working on my SCWCD so I can be a J2EE consultant earning millions of dollars and showing everyone I can

Final variable can be changed, if you are talking about the variables of any object type.
Means we can change the members of that final variable but we can not change the reference.

For example suppose we have below class:

and we have declared it final as:

Even this variable is final but still be can change the value of variable i like

but we can not change the reference like:

means we can not reassign the object.

Final means we can not change the value of the variable and in case of object variable this value is always a reference to an object on heap. So here we can not change the reference but still it is legal to change the underlying variable states.

vinayak chobe

Greenhorn

Posts: 6

posted 6 years ago

I think it means that If a final variable holds a reference to an object then state of the object may be changed but the variable will always refer to the same object

Vinayak Chobe
SCJP 1.4

Swagato Bhatta

Ranch Hand

Posts: 72

posted 6 years ago

Harpreet Singh janda wrote:Final variable can be changed, if you are talking about the variables of any object type.
Means we can change the members of that final variable but we can not change the reference.

For example suppose we have below class:

and we have declared it final as:

Even this variable is final but still be can change the value of variable i like

but we can not change the reference like:

means we can not reassign the object.

Final means we can not change the value of the variable and in case of object variable this value is always a reference to an object on heap. So here we can not change the reference but still it is legal to change the underlying variable states.

Honestly! I never thought this deep! Wow! Thanks

Working on my SCWCD so I can be a J2EE consultant earning millions of dollars and showing everyone I can