This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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: 43950
    
  33
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: 43950
    
  33
You’re welcome
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: static variable
 
jQuery in Action, 3rd edition