aspose file tools*
The moose likes Beginning Java and the fly likes Declaring  static variable only in static method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Declaring  static variable only in static method" Watch "Declaring  static variable only in static method" New topic
Author

Declaring static variable only in static method

PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212

In one of the site i read this statement :

you can declare static variable only in static method .

Except a class and static methods , no other can contain static data .


But when i tried this , its not compiling (Trying to declare a static variable in a static method)


Not Compiles

Please tell me is the statement wrong or i am i missing something?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18669
    
    8

It's wrong. You can only declare static variables at the top level of a class. Variables you declare inside methods are called local variables and can't be static.

Either you misinterpreted what you read on that site or it's a very bad source of Java information.
PavanPL KalyanK
Ranch Hand

Joined: Feb 28, 2009
Posts: 212
Thank you very much paul .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Declaring static variable only in static method