In Java instance and static (class) variables are initialized to default values. Local variables are not initialized. Also, in the example above if you don't have the initial declaration of ServerSocket then it is not in scope in the catch block and won't compile for that reason.
public static void main(String[] args) {
Integer i;
int j = 1;
if (j > 0)
i = new Integer(10);
String s = i.toString();
}
The code above shows the problem
Temp.java:13: variable i might not have been initialized
String s = i.toString();
If you make j final (final j = 1;) then all is fine.
|