aspose file tools*
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
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: 39436
    
  28
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: 39436
    
  28
You’re welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: static variable