At line 4 compiler error is there. I thought Line 4 print statement's i is of local scope of for loop, not method variable that is not initialized. Please focus on this issue.
This is from the Java Language Specification 14.4.2.
The scope of a local variable declaration in a block (�14.4.2) is the rest of the block in which the declaration appears, starting with its own initializer (�14.4) and including any further declarators to the right in the local variable declaration statement.
The name of a local variable v may not be redeclared as a local variable of the directly enclosing method, constructor or initializer block within the scope of v, or a compile-time error occurs.
int i; is declared in the main() method. So its a local variable. and you are trying to create another local variable in for() loop block. but its a local to the main() method also.
And that is of course not allowed....!!! That's why the compiler is complaining. [ April 08, 2007: Message edited by: Vishal K Patel ]
The name of a local variable v may not be redeclared as a local variable of the directly enclosing method, constructor or initializer block within the scope of v, or a compile-time error occurs.
Could you please give me an example of this kind of compiler error and specially done bold.