• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

final variables

 
Reshadee Weerasooriya
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please someone explain why this program gives a compile error.
class Example{
public static void main(String args[]){
final int x;
x=101;
int y;
if(x>100){
y=-1;
}
System.out.println(y);
}
}

 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Reshadee, welcome to the Ranch!

Please post the compiler error text. Does the error message have anything to do with the final variable x?

Oh and before you post any more code, you might like to learn how to UseCodeTags <- link
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is that code so similar to the code in this thread and this one?
Please always tell us where code comes from.
 
Henry Wong
author
Marshal
Pie
Posts: 21022
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Why is that code so similar to the code in this thread and this one?
Please always tell us where code comes from.


And likely, this one too. There seems to be a large group asking the same similar questions, at the same time -- probably caused by the people taking the same class.

So, this is a reminder to all ranchers, please SearchFirst. Your question may already been answered.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic