File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 4543
    
    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: 38851
    
  23
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: 18840
    
  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