class returntest
{
public static void main(String...args)
{
int a;
System.out.println(a); //Line 1
int b[] = new int[10];
System.out.println(b[1]); //Line 2
}
}
I get a compiler error (obviously) at Line 1 stating that the variable may not have been initialized.
I know all int array elements are initialized to 0 by default (so Line 2 compiles successfully) but my question is why cant compiler apply the same logic (of setting to 0 for all ints) to regular (non-array) int variables.
Is there any limitation that prohibits the compiler from doing that ?
returntest) even for dummy code - it's just less distracting that way.