1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Multiple main functions in java

Discussion in 'Java' started by aryan123, Aug 11, 2011.

  1. aryan123

    aryan123 New Member

    Joined:
    Jan 9, 2011
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    0
    Can there be more than one main function in the same class of java??

    Some say it is not possible because compiler will get confused which " main " should be considered for starting the program..

    Some say that it is possible by using different signatures, now what does that mean?
    ( I think it could be : MaIN or mAIN or MaiN etc )
    And the " main " will remain main in this manner.

    please help!
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    By different signatures does not mean different capitalization as that is anyway different functions as Java is case sensitive but different signatures means the parameters would be different.
     
  3. aryan123

    aryan123 New Member

    Joined:
    Jan 9, 2011
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    0
    public static void main(String args[])

    Can there be multiple main functions in a same class?

    Return type of main is always void.
    Argument is always string.
    Then how can one create a function whose name is main and is used for some other purpose,
    i hope u got what i am trying to discover
     
  4. ManzZup

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    may be something like Main
    public static void Main

    :D
     
  5. aryan123

    aryan123 New Member

    Joined:
    Jan 9, 2011
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    0
    int main(x,y)

    is it allowed?
     
  6. ManzZup

    ManzZup New Member

    Joined:
    May 9, 2009
    Messages:
    278
    Likes Received:
    43
    Trophy Points:
    0
    Occupation:
    Production Manager:Software @ ZONTEK
    Location:
    Sri Lanka
    Home Page:
    i just saw that this is still open
    yup, above is perfectly legal

    the java compiler looks ONLY for the main method with the following signature
    main(String[]) / main(String...)

    as long as you define the main method in a different way there's no problem
    but i wont do that becuase it is not a very good proactise
     
  7. aryan123

    aryan123 New Member

    Joined:
    Jan 9, 2011
    Messages:
    22
    Likes Received:
    0
    Trophy Points:
    0
    I have been checking this query regularly.
    U cleared my doubt. Thanks a lot sir !!
     

Share This Page