| Author |
final variable question from kb
|
Dinesh Tahiliani
Ranch Hand
Joined: Aug 06, 2007
Posts: 486
|
|
Rancher, Need your help in this class Knowing { static final long toth = 343L; static long doit(long tooth) { System.out.println(++tooth); return ++tooth; } public static void main(String [] a) { System.out.println(tooth); final long tooth=340L; newkKnowing().doit(tooth); System.out.println(tooth); } } o/p 343,341,340 Can anyone expalin me this How can final variable been modified
|
Thanks<br />Dinesh
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Dinesh, after 349 posts, it's time you learn the beauty of Code Tags. Please use these whenever posting code. There are 3 different variables called "tooth" in this example: A final variable in the class Knowing.A non-final local variable in the method doit.A final local variable in the method main.Keep in mind that whenever you pass a primitive to a method, you are passing a copy of that value, which is assigned to a local variable.
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
Dinesh Tahiliani
Ranch Hand
Joined: Aug 06, 2007
Posts: 486
|
|
|
which value is here than pass ??
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
|
a copy of the final variable, not the final variable itself.
|
[My Blog]
All roads lead to JavaRanch
|
 |
Dinesh Tahiliani
Ranch Hand
Joined: Aug 06, 2007
Posts: 486
|
|
|
In this case will be what 340L or 343L ???
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
First, And then With all the comment, can you figure out what is going to be output ?
|
 |
Dinesh Tahiliani
Ranch Hand
Joined: Aug 06, 2007
Posts: 486
|
|
|
Thanks for excellent reply...
|
 |
 |
|
|
subject: final variable question from kb
|
|
|