public class HelloWorld{ //Why is it throwing error here
final static int i;
public static void main(String []args){
int i = call(10);
System.out.println("Hello World"+i);
}
static int call(int y){
int r= y;
return r ;
}
}
For the above program the use of final static int i;
throws below error. Can anybody exactly tell me why is it. the same final static int i;
works fine when declared inside a method.
Error:
$javac HelloWorld.java 2>&1
HelloWorld.java:1: error: variable i might not have been initialized
public class HelloWorld{
^
1 error