File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes initialization error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "initialization error" Watch "initialization error" New topic

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:
subject: initialization error
It's not a secret anymore!