wood burning stoves 2.0*
The moose likes Java in General and the fly likes final variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "final variables" Watch "final variables" New topic
Author

final variables

Reshadee Weerasooriya
Greenhorn

Joined: Oct 28, 2012
Posts: 1
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

Joined: May 03, 2008
Posts: 4523
    
    5

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


luck, db
There are no new questions, but there may be new answers.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37943
    
  22
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
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: final variables
 
Similar Threads
Inner Classes
Question on warnings/error
initialization and if
Final variables initializing
local final variable