This content has been marked as final. Show 5 replies
This is a bit strange indeed; I ripped the following clause right from the JLS (paragraph 12.1.4)
The method main must be declared public, static, and void. It must accept a single argument that
is an array of strings.
So a private static void main(String args) should fail according to the 'law'.
but it compiles as well as runs correctly its really a strenge !!!!!
What version of java are you using? Prior to 1.4 (or may be 1.3) java allowed public or private to be specified for the main() method and it treated it as public.
Both the JLS and the JVM specs require that the main method to be public (note however that you are allowed to have a private, static, void method that takes a single String-array argument, but it should not be considered an application entry-point).
This was a bug introduced into Sun's VMs with early 1.2 releases; Originally there was no intention to fix it, but eventually they decided to do so, and it was fixed for 1.4.
If you do not declare your main methods public, static and void, you will find that your applications stop working one day when you switch Java versions, or when you roll the code out to clients using a different version to that which you developed and tested the apps on.
corrently i am working on 1.4 version and if i write
public class U
private static void main(String args)
it compiles and when i run this program it shows "Main method not public" I think bug is fixed now.