+ 1

Is it important that java program should have main () method??is it possible that program may run without main()

20th May 2017, 4:06 AM
harshita koshta
harshita koshta - avatar
2 Answers
+ 16
/* No, it's not necessary with respect to Java7(http://stackoverflow.com/questions/15173474/can-we-execute-a-java-program-without-a-main-method) : If there's code in a static block, it will be executed. But there's no point in doing that. */ public final class Test { static { System.out.println("FOO"); } } /* Then if you try to run the class (either form command line with java Test or with an IDE), the result is: FOO java.lang.NoSuchMethodError: main */ // It's not supported here in the Code. P.
20th May 2017, 4:21 AM
Dev
Dev - avatar
0
thank u so much
20th May 2017, 4:23 AM
harshita koshta
harshita koshta - avatar