Hi
we want put two main method in a single class in java its possible or not
Can be put two main method in the same class in java if yes than give the example?
1 Answer
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jan 30, 2012, 1:05 AM EST
1. By overloading the main() method so that each overload takes different types and/or numbers of parameters .
2. By placing an additional main() method, or overloads thereof, within a nested class of the class which contains the main() method.
Though why you'd want to do that, other than as an exercise, I cannot imagine.