As many as you want. In fact, all your classes can have main() methods if you so desire(although I don't think it would earn you any points for clarity). The main() method executed will be that of the class you specify on the command line when you start java. Junilu
Hi, My other question was abt having how many Main() classes in the application... and unfortunately it was moved to Java(beginner's)forum. I know an application can have any number of main classes, but thats not what i meant. Based on my Understanding of programming FOR ANY APPLICATION to be good, there can be only ONE main class, or a SINGLE executable class. And there should be ONLY ONE class through which you can execute or run the application. Then only that application is said to be designed well. right?! But i had 2 main classes in my application. So i wanted to find out if i was the only one to do that or is someone else doing like me? Anyway, thanks for the answer, sri
As already posted, you can have a main class for every class in your application. It can be used to test the functionality of each class, during development. The key thing is that of all your main classes, only one of them can be public, and this is the one that will drive the application, and the class name must match the name of the file that contains it.
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
I agree with Bosen! For clarity sake you should only have one main() method or main class...you can get into overloading the main() which is a totaly different method and things can get pretty confusing. The only main() that runs is the main() method that takes a string array! others would usually have to be called with appropriate arguments. You must have one main(with the appropriate array) in your application. haha too early for me! thanks guys Aaron - SCJP2 [ May 29, 2002: Message edited by: Aaron O'Brien ] [ May 30, 2002: Message edited by: Aaron O'Brien ]
Originally posted by Aaron O'Brien: You must have one no args main() in your application.
Perhaps you meant: You must have one main method that takes a String array as its only argument. There is no requirement for a no args main method. In fact, the presence of such a method might lead to some confusion.