I was asked this question in an interview.
How to print message on console without using main() method?
class MainMethodNot
{
static
{
System.out.println("Hello World");
System.exit(0);
}
}
Because the static initializer block is executed when the class is first loaded, we can print out “Hello World” without writing a main method. The execution is stopped using “System.exit()” command. So, we prevent “main method not found” error. It's quite a tricky question