Nandkumar Tekale Nandkumar Tekale - 1 year ago 104
Java Question

Printing message on Console without using main() method

I was asked this question in an interview.

How to print message on console without using


Answer Source
public class Foo {
    static {

The System.exit(0) exits program before the jvm starts to look for main()

Ideone link

(Note: even if it compiles with JDK 7's javac it cannot be run with its java, because it expects a main(String[]) method.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download