aspose file tools*
The moose likes Java in General and the fly likes How a static main method, calls other non-static member methods of its class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How a static main method, calls other non-static member methods of its class?" Watch "How a static main method, calls other non-static member methods of its class?" New topic
Author

How a static main method, calls other non-static member methods of its class?

Akshay Kumar
Ranch Hand

Joined: Feb 24, 2004
Posts: 37
As i read in the books that static methods can access only other static variables/methods, but how is it in the case of main method?
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
A static method can neither access non-static variables nor can call non-static methods. main() method is no exception.
Try this code

To access the myMethod() from main, you need to create an instance of MyClass and call it.

Same case with the non-static data also.
[ February 24, 2004: Message edited by: Mani Ram ]

Mani
Quaerendo Invenietis
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How a static main method, calls other non-static member methods of its class?