Hi friends
I want to know that can we make more than one main function in a single java file. How to run every class in this file.
Thank you.
Loading
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 Apr 9, 2012, 10:29 AM EDT
Vipendra VermaRank #473 · 5.3K reputationPosted Apr 9, 2012, 2:47 PM EDT
VulpesRank #55 · 29.2K reputationPosted Apr 10, 2012, 1:59 AM EDT
If you compile this program with JDK 1.6, two class files will be generated - MyClass.class and YourClass.class.
If you then run MyClass, you should see the following output:
Hello from MyClass
Hello from YourClass
The program will also work without error if you run YourClass but the output then will be the single line:
Hello from YourClass