aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes LOCAL VARIABLE Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "LOCAL VARIABLE" Watch "LOCAL VARIABLE" New topic
Author

LOCAL VARIABLE

Jaya Murugan
Ranch Hand

Joined: Nov 18, 2000
Posts: 34
=========================================
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
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

------------------
author of:


Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: LOCAL VARIABLE
 
Similar Threads
LOCAL VARIABLE
why am i not getting output
a simple question
Package level question.
LOCAL VARIABLE