Hi there,
using JWhiz I found explained that you can't mix the declaration
of local for-loop variables and external variables.
But check out the following two class definitions MyClass1 and MyClass2.
The only difference is the location of 'int i;'
public class MyClass1
{
public static void main(
String[] args)
{
for( int i = 0; i <= 2; ++i )
{
System.out.println(i);
}
int i;
}
}
public class MyClass2
{
public static void main(String[] args)
{
int i;
for( int i = 0; i <= 2; ++i )
{
System.out.println(i);
}
}
}
The question is:
Why is MyClass1 compiled without error while the compilation
of MyClass2 leads to the following compiler message:
MyClass2.java:7: i is already defined in main(java.lang.String[])
for( int i = 0; i <= 2; ++i )
^
1 error
Thanks in advance
Ruediger