my dog learned polymorphism*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
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://aspose.com/file-tools
 
subject: initialization error
 
Similar Threads
char
Doubt in K&B SCJP 5: Chap 2, SELF TEST, Q 11
Not operator
abstract class instantiation
static variable confusion