Pramod P Deore wrote:No, you can't do that. If you want to print message then you have to use static initialization block but after execution of block exception will be throw as NoSuchMethodError: main,
Not if you exit before that ;)kulbhushan, why do you think you need to do this? (Hint: you don't)
edit I like David's sysout better!
There are no new questions, but there may be new answers.
Any good manager will fire you on the spot if you ever use that trick in anything other than example code. After all, if the class is loaded it will execute the code in the static block and then terminate the JVM. This will also happen if I ever try to instantiate NoMain (new NoMain()) or call a static method on it.
As stated before you need a main method if running a "standard" standalone Java program.
But quite often Java application run inside a container that defines a lifecycle by calling special methods. E.g. if you run an applet the methods init, start, stop and destroy are called at specific times. (If you add a main method you could run an applet both within an applet container and standalone.) Another example for an application within a container and with a lifecycle would be a web application that runs within a server, e.g. Tomcat.
If the container is written in Java, though, there still will be a main method ;-).