CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: main method

  1. #1
    Join Date
    Sep 2011
    Posts
    197

    main method

    There must be some expceptoins when it comes to main methods correct? Like there are certain circumstances where main methods aren't nessasary or needed. I would be very appriciateive if someone could lay them out for me.

  2. #2
    Join Date
    May 2011
    Posts
    41

    Re: main method

    your question is a little vague. And the answer would be enormous. What exactly are you trying to accomplish?

  3. #3
    Join Date
    Sep 2011
    Posts
    197

    Re: main method

    Okay sorry haha..

    Revamped question:
    Can you have a class without a main method (that will compile, and work)?

  4. #4
    Join Date
    May 2009
    Posts
    2,413

    Re: main method

    Quote Originally Posted by kolt007 View Post
    Can you have a class without a main method (that will compile, and work)?
    Sure, you only need one class with a main method. The main method is the so called program entry point, that is where the program starts.

    But you can have several main methods (each in a different class) if you wish. Then the program will have many entry points and you must select which one you want when you start the program.

  5. #5
    Join Date
    Jun 1999
    Location
    Eastern Florida
    Posts
    3,877

    Re: main method

    You need to have the standard main method in any class you try to start by using the java command:

    java ThisClassMustHaveMainMethod
    Norm

  6. #6
    Join Date
    Jan 2011
    Posts
    24

    Re: main method

    public static void main(String args[]) method is only needed to run the program , there is no need for compiling a class. in java an empty class is also valid and compile

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured