This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Have you tried it? That's the best way to answer a question like this. Every class in your system can have a "main" method if you want it to. That's why when you run a Java program you must specify which class to start with - the interpreter runs the "main" method in the named class
hi, yes i have tried it and it does compile and run. the question arises that is each class in itself a driver program now ... i dont kno bout lots of other OOPs architecture but is this deliberately a part of the JVM architecture. coz the other langs i kno support only one main. or is it that such a thing does not create any probelms in the design of a program.
Yes, it is intended to be this way. One of the benefits that this can provide is allowing the classes that are not "conceptually" the driver class to still have a main. This main is then loaded with a bunch of stuff to self-test that particular class. Even though you leave it in the production code, it will never get executed because you don't kick off the application using that class.
"JavaRanch, where the deer and the Certified play" - David O'Meara
Joined: Jan 31, 2001
hi cindy, ur explanations as always are very helpful. thanx a lot.