I was asked this question in an interview.
How to print message on console without using main() method?
If you don't want to use static block too, it can be done following way
public class NoMain {
private static final int STATUS = getStatus();
private static int getStatus() {
System.out.println("Hello World!!");
System.exit(0);
return 0;
}
}
However, please note that this is for Java 6 version. Its not working in Java 7 which is said to be supported in Java 8. I tried with JDK 1.8.0_77-b03, which is still not working