variable initialization problem
Hi guys.........
I have a small problem, basically fundamental problem.
public class Compile15 {
public static void main(String args[]){
int i1=9; //3
int i2; //4
if(i1>3){
i2=8;
}
System.out.println(i2);
}
}
In this above program when I try to run this program, it occur compile time error -- "variable i2 might not have been initialized" ,although within if condition I have initialized i2.
Now if I initialize i2=0 at line 4 it runs perfectly or at line 3 if I declare variable i1 as final int i1 without changing at line 4 then it will compile and run also.
I'm not so cleared about these two solutions. Please someone clarify this for me in details.
Thank you................