File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Regarding static Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regarding static" Watch "Regarding static" New topic

Regarding static

santhosh kumar vk
Ranch Hand

Joined: Aug 25, 2009
Posts: 151

I have one doubt that is in static method we can not use non static variable then how it is possible in public static void main(String args[]) can you explain

Thanking you.
John de Michele

Joined: Mar 09, 2009
Posts: 600

It isn't possible in a main() method, either. However, you can create a local instance like this:

Running the main() method should print out 'bar'.

pankaj vijay
Ranch Hand

Joined: Apr 01, 2008
Posts: 75
in static method we cann't access instance(non static) variables. but when you are in static method you can not declare static variable BUT you can declare local variable that will be non static. As static variable belongs to class not to method.

Pankaj Vijay (SCJP, SCBCD)
Learn Core Java,Learn Servlet Jsp, SCJP Questions,Struts Tutorial
I agree. Here's the link:
subject: Regarding static
It's not a secret anymore!