File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How a static main method, calls other non-static member methods of its class?
 
Similar Threads
Why main( ) is declared as static?
Static Method
doubt in static
Java static Method
Doubt: Main method