wood burning stoves*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regarding static" Watch "Regarding static" New topic
Author

Regarding static

santhosh kumar vk
Ranch Hand

Joined: Aug 25, 2009
Posts: 144
Hi

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
Rancher

Joined: Mar 09, 2009
Posts: 600
Santhosh:

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'.

John.
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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Regarding static
 
Similar Threads
Using static
Static Method Overriding
doubt about import static
overloading static methods?
question about ArrayList