Strange Behavior in final variable in Java -
this question has answer here:
in java program have used 1 final variable.we know value of final variable fixed , can't changed.so why particular program working fine?can explain.
public static void main(string args[]) { int[] integerarray = { 1, 2, 3, 4, 5 }; (final int j : integerarray) { system.out.println(j); } }
it's final within body of loop - you're declaring different variable each iteration of loop.
it's if you'd written this:
for (int = 0; < integerarray.length; i++) { final int j = integerarray[i]; system.out.println(j); } again, have "new" local variable called j on each iteration of loop... each of variables never changes value.
Comments
Post a Comment