adspace


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 do you mean by an interface in java?

1110


What is a classloader in java?

1101


What is the difference between break and continue statements?

1135


What is parsing in java?

1052


Realized?

2278


Is minecraft 1.15 out?

1056


What is java string pool?

1091


Write a program to print count of empty strings in java 8?

1095


Write a java program to find the route that connects between Red and Green Cells. General Rules for traversal 1. You can traverse from one cell to another vertically, horizontally or diagonally. 2. You cannot traverse through Black cells. 3. There should be only one Red and Green cell and at least one of each should be present. Otherwise the array is invalid. 4. You cannot revisit a cell that you have already traversed. 5. The maze need not be in the same as given in the above example

2677


What is a constructor overloading in java?

1136


What are the differences between heap and stack memory in java?

1152


What is an object in java and how is it created?

1153


Write a program to find the whether a number is an Armstrong number or not?

1110


Differentiate between static and non-static methods in java.

1135


How to create a base64 decoder in java8?

1152