========================================= public class test1{ public static void main(String args[]){ int x =10; int y; if(x > 5) y =0 System.out.println("y"+y); } } ========================================== public class test2{ public static void main(String args[]){ int x =10; int y; if(x > 5) y =0 else y = 1; System.out.println("y"+y); } } ================================= test1 says the variable is not initialised. test2 works fine. i dont know why??? pls helps........regards......Jaya Murugan
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
1
posted
0
In the code: public static void main(String args[]){ int x =10; int y; if(x > 5) y =0 System.out.println("y"+y); } The compiler determines that there is a logical path in which y is never initialized. In order for it to determine that y is always initailized for the particular value of x that is set, the compiler would have to actually execute the program. Obviously impossible, so it gives the warning. Bill