Possible Duplicate:
Uninitialized variables and members in Java
Why are local variables not initialized in Java?
In Java
variables have default value, right? Even arrays are initialized by compiler.
So I can't understand the following:
int c;
for(int i = 0; i < 10; i++){
c = i + 5;
}
System.out.println("Result = "+c);
Why do I get a compiler error:
The local variable c may not have been initialized
Isn't c
initialized to 0
by default by compiler?
So why do I get this error and why does the error go away if I explicitely do int c = 0
?