I know that local variable have to be initialized explicitly. The behaviour of tehse two programs is confusing me. Please help.
-----------------------------------------
public class local1
{
public static void main(
String args[])
{
int x=100;
int y;
if(x<10)
y=1;
if(x>=10)
y=2;
System.out.println("Y is"+y);
}
}
This tells me y is not initialized.
--------------------------------------------
public class local2
{
public static void main(String args[])
{
int i,j;
int k=0;
j=2;
k=i=j=1;
System.out.println("K is"+k);
}
}public class local2
{
public static void main(String args[])
{
int i,j;
int k=0;
j=2;
k=i=j=1;
System.out.println("K is"+k);
}
}
This compiles fine.
-----------------------------------------------
Can someone explain???
Thanks