With out main

public class Demo{
    static
    {
        System.out.println("hello");
        System.exit(0);
   }
    }
}

Since we know that all static block executes first at the time of class loading in class loader so this program prints hello before going to main .
this program will executes in the java versions which had coming before java 1.7
But this will doesn't work with java 1.7 since in java 1.7 concept change ..
in java 1.7  control goes first to main then executes all static blocks.

No comments:

Counters