wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Static method - Non static variables" Watch "Static method - Non static variables" New topic
Author

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
Regards,
aakash
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
 
 
subject: Static method - Non static variables
 
Similar Threads
non-static inner classes
Can somebody explain why this is legitimate?
Reg. class initialization sequence
non-static methods
Static variables in inner class not allowed why?