0
Is a main method compulsory in all Java programs?
In the second question of the module quiz of basic Java, all the three options are wrong. However, the second option has been set as correct. Java need not have a main method!
4 odpowiedzi
+ 14
yes
//thats the starting point of java program , from where the compiler starts compiling.
//if no main method , then there must be someOther method to define the starting pt.
+ 2
main method is kinda important its the start of execution 😊
+ 1
Yeah, I get your point, but main method is not compulsory as such. We can write programs without a main method and use them in some other Java programs or as a web backend.
+ 1
If you don't write main method then you will get run time exception.
Prior to jdk 5, you can write some code under static block and terminate the program right there. But after jdk 5, it is compulsory to write main method. Otherwise you will get run time exception saying main method not found