File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java 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 » Beginning Java
Bookmark "static variable" Watch "static variable" New topic

static variable

vikas mhatre

Joined: Apr 24, 2010
Posts: 26
As I know we can't access instance variable from static method.

Here a and b both are not static still we can access b but not a why?
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 61959

b is neither an instance or a static variable. It's a local variable to the method and is in scope from its declaration to the end of the method.

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
rewati raman
Ranch Hand

Joined: May 22, 2010
Posts: 62
a and b are not static as static key word is not used.
b is a local variable and can be accessed in main method. where as a can be accessed through out the class test.
vikas mhatre

Joined: Apr 24, 2010
Posts: 26
Thanks Bear
I agree. Here's the link:
subject: static variable