File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Final Variable Declaration

 
ZEESHAN AZIZ
Ranch Hand
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am little confused about initializing final variables.
KM says
"final variable need not be initialized at its declaration, but it must be initialized before it is used"
In code below, I am not using final variable at 2, still I am getting compiler error that variable is uninitialized, why is it so
public class q{
static int x;
final static int y;//2
public static void main(String args[]){
System.out.println(x);

}
}
 
Mikael Jonasson
Ranch Hand
Posts: 158
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Final variables doesn't have to be initialized on declaration, but they must be initialized no later then at the constructor for the class they are in.
/Mike
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic