Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / harathi

We can have multiple main methods with different
arguments.Compiler throws an error if we have a method
similar to public static void main(String args[])

Is This Answer Correct ?    21 Yes 3 No

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

Answer / aburar yaseen

we can use multiple main methods in a class by overloading
and not by the overriding. but the overriding is possible
in case of parent child combination.

example:
class xxx{

public static void main(String args[]){}
void main(){}
}
the above is called overloading.

example2;
class xxx{
public static void main(String args[]){}
}
class yyy extends xxx{
public static void main(String args[]){}
}
the above is overriding.
example3;
class xxx{
public static void main(String args[]){}
public static void main(String args[]){}
}
the example3 is not possible
}

Is This Answer Correct ?    16 Yes 3 No

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

Answer / pranab dutta

No the program fails to compile, if you have multiple main
methods in the same class. The compiler says that the main
method is already defined in the class.

Is This Answer Correct ?    18 Yes 8 No

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

Answer / bindhu

The compilation error " main(lava.lang.String[]) is
already defined " will occur when we use have multiple main
methods in the same class?

Is This Answer Correct ?    12 Yes 2 No

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

Answer / nisha

The compilation error, if you have multiple main
methods in the same class.
Error like :java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable source
code - main(java.lang.String[]) is already defined

Is This Answer Correct ?    1 Yes 0 No

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

Answer / devarathnam c,kotagudibanda(po

No error

Is This Answer Correct ?    5 Yes 6 No

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

Answer / someone else

this is not overriding,,,,,it is over hidding

Is This Answer Correct ?    1 Yes 5 No

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

Answer / jhonty

this is called data hiding.

Is This Answer Correct ?    0 Yes 4 No

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

Answer / srikanth

No, there is no error if we have multiple main methods
in the same class.
because, while compiling we only specify one main method
name so, the JVM compiles it by taking the main method which
is specified by us while compiling.

Is This Answer Correct ?    3 Yes 23 No

Post New Answer

More Core Java Interview Questions

Why java is platform independent? Explain.

0 Answers  


What is the difference between variable declaration and variable initialization?

0 Answers  


What is the use of set in java?

0 Answers  


When do we use synchronized blocks and advantages of using synchronized blocks?

0 Answers  


how can u handle run time exception in java? explain with brief explanation with examples?

2 Answers   CTS,


Implementations of set interface?

0 Answers  


What is meant by method overriding?

0 Answers  


What are the types of collections in java?

0 Answers  


What is skeleton and stub? What is the purpose of those?

0 Answers  


Which One is optimal to choose ? Syncronized hash map or Hash table with single thread model? How can a hash map syncronized with out using syncrozed blocks in programm?

3 Answers   Four soft,


What are different types of arrays?

0 Answers  


what is the purpose of "virtual"?

0 Answers   EDS,


Categories