Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Java (http://www.go4expert.com/forums/java/)
-   -   Multiple main functions in java (http://www.go4expert.com/forums/multiple-main-functions-java-t26480/)

aryan123 11Aug2011 12:40

Multiple main functions in java
 
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!

shabbir 11Aug2011 13:22

Re: Multiple main functions in java
 
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.

aryan123 11Aug2011 16:19

Re: Multiple main functions in java
 
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

ManzZup 13Aug2011 21:21

Re: Multiple main functions in java
 
may be something like Main
public static void Main

:D

aryan123 13Aug2011 22:47

Re: Multiple main functions in java
 
int main(x,y)

is it allowed?

ManzZup 25Aug2011 21:25

Re: Multiple main functions in java
 
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

aryan123 26Aug2011 23:47

Re: Multiple main functions in java
 
I have been checking this query regularly.
U cleared my doubt. Thanks a lot sir !!


All times are GMT +5.5. The time now is 12:54.