File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Akshay Kumar
Ranch Hand
Posts: 37
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1140
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic