• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

public static void main()

 
Nilanjan Sahu
Greenhorn
Posts: 3
  • 0
  • 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
Pie
Posts: 12022
25
Chrome Java Linux
  • 0
  • 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
}

}
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic