class WithOutMainMethod{
static {
System.out.println("Hello world!");
System.exit(0);
}
}
*static block executed once by JVM when class loaded.
*System.exit(0) it say jvm to exit .
*If you are not giving System.exit(0) ,Hello World will print and give some Execption like
Exception in thread "main" java.lang.NoSuchMethodError: main.
No comments:
Post a Comment