posted 19 years ago
First of all, it is perfectly legal to have a class with no main method. The purpose of the main method is to indicate a "point of entry" into the code. Without a main method, where would you start executing your code?
If you don't declare a main method, you simply can't execute that class from the command line. However, there's nothing stopping other classes from using it. Here's an example:
As far as having a private main method goes, you can do that, too. The key here is that, when the JVM tries to begin execution of a class, it will look for a method with the signature "public static void main(String[] args)". If your main method is declared as private, the JVM will not be able to execute it.
*Caveat: There have been known issues in the past in which compilers would execute a non-public main method. I would interpret this as a "bug" as the JLS clearly states that the entry for execution must have the signature "public static void main(String[] args)". If you get this question on the exam, go with what the JLS states.