This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes initialization error Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "initialization error" Watch "initialization error" New topic
Author

initialization error

Harvinder Singh
Ranch Hand

Joined: Feb 14, 2003
Posts: 90
//even when the y is declared outside compiler says that value of y is unassigned.Is this error is because y is a local variable of main() method
or is there any other reason.thanks.

public class Compare2{
public static void main(String args[]) {
int x = 10, y;
System.out.println("y is " + y);
}
}


Hard work beats talent<br />when talent doesn't work hard.<p> - Tim Notke
Munish Gulati
Ranch Hand

Joined: Aug 06, 2003
Posts: 37
Yes you are right, local variables are to be initialized explicitly.


Munish Gulati<br />SCJP 1.4<br />Albert Einstein: There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: initialization error
 
Similar Threads
Not operator
static variable confusion
char
Doubt in K&B SCJP 5: Chap 2, SELF TEST, Q 11
abstract class instantiation