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
What is a container in a gui?
How to retrieve data from database in java using arraylist?
Difference between arraylist and vector.
What are advantages of using Java?s layout managers than windowing systems?
What is java util?
Does list maintain insertion order java?
What is difference between char array and string?
Explain the purpose of garbage collection in Java?
How to print an arraylist in java?
What is the difference amongst jvm spec, jvm implementation, jvm runtime ?
What are the super most classes for all the streams?
What is Java Package and which package is imported by default?
What is the major difference between linkedlist and arraylist?
When a thread is executing synchronized methods , then is it possible to execute other synchronized methods simultaneously by other threads?
2) Suppose there are 5 directories having lot of files (say txt files) in each directory. 2 things :- 2.1) You want to search for filenames which have a particular pattern. 2.2) Out of these filtered files you want to search for a particular keyword or a search string. How can you achieve this?