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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "static variable" Watch "static variable" New topic
Author

static variable

soumik paul
Greenhorn

Joined: Jan 14, 2013
Posts: 5
Can anyone explain me why we cannot declare a static variable inside a method? Is it because static variables are class level variables?
Kemal Sokolovic
Bartender

Joined: Jun 19, 2010
Posts: 825
    
    5

What would be the use of it? Variables declared inside the method body are local variables to that method; they can't be accessed outside of it.


The quieter you are, the more you are able to hear.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
Welcome to the Ranch
As KS has told you, there is no point; static members belong to the class, and something declared in the method is a local variable which belongs to the method.
soumik paul
Greenhorn

Joined: Jan 14, 2013
Posts: 5
Thanks for clarifying it fo me.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
You’re welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static variable
 
Similar Threads
why compile error??????/
GUI Big trouble
Statics and serialization
Pl explain this a bit diff code
interface rule