About main function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sasimca007
    New Member
    • Sep 2007
    • 129

    About main function

    Hello friends,
    why we use public static void main() for every program? without static and public it can't be run? Please give me the answer.
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    Originally posted by sasimca007
    Hello friends,
    why we use public static void main() for every program? without static and public it can't be run? Please give me the answer.

    static @ main is design for the VM to search the main method who activates the the components etc... to be executed first...

    it must be public @ main so that the invoker java.exe could execute the main method...

    whenever there is a public class but the methods inside is private, you cannot access them...And so as the VM....

    if you are not satisfied, ask Sun MicroSystems Java Head Developer...

    If im wrong, please correct me!!!

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      I'm fairly certain the main() method is static because it doesn't belong to any particular object. It would be impossible to run if you needed to create an object first, then run the main method, because where would you create the object?

      Comment

      • hsn
        New Member
        • Sep 2007
        • 237

        #4
        you have a good question i never thought of this question.
        and thanks for the answer

        Comment

        Working...