May be this is a stupid question? Sorry it sounds so. I have following codes.
Condition 1
public class Test {
int a;
void display() {
System.out.println(a);
}
}
Condition 2
public class Test {
void display() {
int a;
System.out.println(a);
}
}
I am very clear about the second condition. The a is not initialized. So, this will produce an error. But in first condition, I've not initialized property a. While running the following code, it will not produce an error. Instead it will display 0. It may be due to integer is initialized to 0.
Test t;
t = new Test();
t.display();
What is the logic behind not to initialize local variable and to initialize property(integer) to 0?