tag:blogger.com,1999:blog-3166332459178575831.post7340949506883067768..comments2024-03-28T16:48:59.256+05:30Comments on JAVA INTERVIEW QUESTIONS: JAVA: What if the main method is declared as private?Anijit Sarkarhttp://www.blogger.com/profile/06042935741690271750noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-3166332459178575831.post-50583820138795148262013-06-26T04:00:21.536+05:302013-06-26T04:00:21.536+05:30Run time errorRun time errorAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-3166332459178575831.post-48936081917925500592012-09-14T23:47:15.935+05:302012-09-14T23:47:15.935+05:30No compile error.
But, main method will not be acc...No compile error.<br />But, main method will not be accessible by JVM. sudhanshunoreply@blogger.comtag:blogger.com,1999:blog-3166332459178575831.post-29593414145939730562012-06-11T18:15:20.407+05:302012-06-11T18:15:20.407+05:30it will compile but we get the error while executi...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.,<br /><br />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.<br /><br />In the same way the JVM calls the main() with class name by using the static keyword.So,static is mandatory to write.bharathhttps://www.blogger.com/profile/11720720750866105174noreply@blogger.comtag:blogger.com,1999:blog-3166332459178575831.post-97749413772359962012-06-06T07:51:39.641+05:302012-06-06T07:51:39.641+05:30what happens main method write like this.... publi...what happens main method write like this.... public void main()surihttps://www.blogger.com/profile/04307331683049429808noreply@blogger.com