+ 1
Is it important that java program should have main () method??is it possible that program may run without main()
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.
0
thank u so much