The method main must be declared public, static, and void. It must accept a single argument that is an array of strings.
Notice that it doesn't say anything about where the body of main is defined. Therefore, it can be native. Note that if main is declared native, it still has a body, it just isn't defined as most method bodies are because it is native. I hope that helps, Corey
Declaring main as private is ok....but it is not ok for the starting point. If you compile it no problem...but run time there will be an error
Nazmul<br />SCJP,SCWCD,IBM OOAD with UML
posted 18 years ago
You can declare main to be whatever you want - private, final, native, whatever. The rules that state that main must be public, static, and take an array of Strings only apply to the main method that you intend to use as an entry point. The JVM will invoke the method that matches that description. The main method you defined above (private) is perfectly legal, but it can't be used as an entry point as the JVM won't have access to invoke it. If you were to try, I'm guessing you'd run into a NoSuchMethodException. I hope that helps, Corey
The Java virtual machine starts up by creating an initial class, which is specified in an implementation-dependent manner, using the bootstrap class loader (�5.3.1). The Java virtual machine then links the initial class, initializes it, and invokes its public class method void main(String). The invocation of this method drives all further execution. Execution of the Java virtual machine instructions constituting the main method may cause linking (and consequently creation) of additional classes and interfaces, as well as invocation of additional methods.
Finally, after completion of the initialization for class Test (during which other consequential loading, linking, and initializing may have occurred), the method main of Test is invoked. The method main must be declared public, static, and void. It must accept a single argument that is an array of strings.
Of course, none of this says what happens in the cast the main method doesn't meet these requirements. As far as the exam goes, however, remember that main must be public, static, and take an array of Strings. Corey