Sunday, 15 January 2012
JAVA: What if the main method is declared as private?
Do you like this Article?
The program compiles properly but at run-time it will give "Main method not public." message
Subscribe to:
Post Comments
(
Atom
)
4 Responses to “ JAVA: What if the main method is declared as private? ”
6 June 2012 at 07:51
what happens main method write like this.... public void main()
11 June 2012 at 18:15
it will compile but we get the error while executing the code with an error as "NoSuchMethodError".because the JVM calls the main() by the class name with static keyword.i.e.,
Note:With static keyword we can call the any method by using class name itself,no need of any object creation and calling the respective method.
In the same way the JVM calls the main() with class name by using the static keyword.So,static is mandatory to write.
14 September 2012 at 23:47
No compile error.
But, main method will not be accessible by JVM.
26 June 2013 at 04:00
Run time error
Post a Comment