Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

public static void main()  RSS feed

 
Nilanjan Sahu
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i read in many reputed books and also seen that a static function cal call only static members but in java public static void main() can call all functions. How?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12440
42
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
a static method can only access static members... or constructors. Once you construct the object, you can call it's non-static methods. a common idiom you'll see is

public class SomeClass {
public static void main(String args[]) {
SomeClass myInstance = new SomeClass();
myInstanct.callAMethod();
}
public void callAMethod(){
//do something
}

}
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!