Is there is any error if you have multiple main methods in
the same class?

Answer Posted / rakesh nath

Well, I think we are going out of the question. The question
is that whether there is any error if we have multiple main
methods. Answer is not necessarily. I would like to change
the question in this way. Will it be possible to have
multiple main methods in the same class? Now the answer is
YES. WE CAN. But there should be only one main method that
has the complete signature "public static void main(String
args[])".

For example,
class Test
{
public static void main(String args[]){....}
public static void main(int args[]){....}
public static void main(boolean args[]){....}
public static void main(Object args[]){....}
}
this code will work without any error.

Remember there should be ONLY ONE main method with the
signature "public static void main(String <varargs>)"
because the compiler searches for this method to be loaded
into the bootstrap loader. If there are multiple methods
with this signature, it will throw an error.

Is This Answer Correct ?    42 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the full meaning of java?

627


What is the purpose of the system class in java?

637


What is the function of static in java?

625


Explain the selection sort algorithm and state its time complexity?

695


What is the maximum size of array in java?

608






What do you understand by synchronization?

678


how to handle exceptions in ejb?

1976


What is a 16 bit word?

660


What access modifiers can be used for methods?

655


What is a method in coding?

666


What is thread count in java?

628


How do you check if a character in a string is a digit or letter?

612


what is the difference between yielding and sleeping? : Java thread

613


What do the thread?class methods run() and start() do?

654


Define linked list and its features with signature?

658