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 Static method - Non static variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Static method - Non static variables" Watch "Static method - Non static variables" New topic

Static method - Non static variables

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
is there any way to access Non-Static variables/methods from a static methd
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Create an object of the class and get them thru the instance. You have to remember that the reason you can't access instance variables and methods from a static context is that static methods are not polymorphic which means that the compiler links the method at compile time, not runtime like. So the compiler has no way of knowing what instance (if any) to use.

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
I agree. Here's the link:
subject: Static method - Non static variables
jQuery in Action, 3rd edition