Because the rules of the JVM say that
when it launches your program, it will look for a public main method in the class you give it.
The JVM could have been designed to not care if the method was public, but it's more consistent with the general use and purpose of the access levels. Whatever is invoking your main is not part of the same class or package, nor is it a subclass, so it makes sense that it should only invoke a public main method.
In the end, though, the real answer, as with all "Why is Java this way?" questions, is, "Because that's what the designers decided on."
when it launches your program, it will look for a public main method in the class you give it.
The JVM could have been designed to not care if the method was public, but it's more consistent with the general use and purpose of the access levels. Whatever is invoking your main is not part of the same class or package, nor is it a subclass, so it makes sense that it should only invoke a public main method.
In the end, though, the real answer, as with all "Why is Java this way?" questions, is, "Because that's what the designers decided on."
Hope above explanation help you....
No comments:
Post a Comment