Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

initialization error

 
Harvinder Singh
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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);
}
}
 
Munish Gulati
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes you are right, local variables are to be initialized explicitly.
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!