*But*, the key here, is what if x == 100? What's the value of y in this case? Uninitialized.
variable i might not have been initialized
I have a doubt on Questions in the SCJP exams regarding difference between warning and error.
all events occur in real time
Originally posted by Burkhard Hassel:
A compile with a warning is still a sucessfull compile.
This code compiles fine!
code:
--------------------------------------------------------------------------------
void method { final int x = 10; // added final
int y;
if (x<100) y = 100;
if (x>100) y = x*10;
System.out.println(y);}
--------------------------------------------------------------------------------
original program
public class GeneralTest
{
public static void main(String arg[])
{
int x=10;
int y;
if (x<100) y=100;
if (x>100) y= x*10;
System.out.println(y);
}
}
This simple program results in compile time error :
GeneralTest.java:9: variable y might not have been initialized
System.out.println(y);
^
1 error
Modified by Ahmed
void method
{
final int x = 10; // added final
int y;
if (x<100) y = 100;
if (x>100) y = x*10;
System.out.println(y);
}