public class Test{
public static void main(String a[]) {
int i1=9;
int i2;
if(i1>3) {
System.out.println(i1);
i2=8;
}
System.out.println(i2);
System.out.println(i1);
}
}
this give an error message that local variable must be initialized.i.e i2
but when we write that code in such a manner
public class Test{
public static void main(String a[]) {
final int i1=9;
int i2;
if(i1>3) {
System.out.println(i1);
i2=8;
}
System.out.println(i2);
System.out.println(i1);
}
}
it does not show any error message . is there any property of final when it used for local variable or something else ..please share your view.
I am Beginner in java. I tried to run this program in eclipse IDE but it gives error when i write first part of program. but it does not show any error when i write second part only change is addition of final keyword. what happens to this code is not understandable by me . explain with reason.