|
|
Re: Public Main
|
Posted: Nov 22, 2004 3:40 PM
|
|
main() method doens't necessarily has to be public. Here is question I sent to Sun and the reply I got (in 2001).
**************************************************** At 08:43 PM 1/22/01, Kishori wrote:
Hi I am running Java2 v1.3. The Java Virtual machine Specification says that to run a class JVM calls public static main(String[] args ) method of the initail class. IN in v1.3 even if the main method is declared as private, or with no modifier, it works. Is it a bug in Java2 v1.3 JVM?
There is no bug, though the specification is perhaps to subtle. If you read JVMS 5.2 carefully, you will understand that the initial class that a user provides (often on the command line) is not the initial class that the spec is referring to. The initial class of the user's program need not be public. The JLS is somewhat misleading in this regard (even though it does refer to the binding specification in the JVMS).
Cheers, Gilad
|
|