I want to "execute" main() method before the static block is called. As per Java rules Static block will be executed when the class is loading and then main() method is called. Is there any way to first "execute" main method and then static block?
public class StaticDemo {
static {
System.out.println("in static block");
}
public static void main(String args[]){
System.out.println("in main method");
}
}
The output will be....
in static block
in main method
calling main method from static block just generate expected output. but it first executed static block and from that it called main method.
import com.sun.javaws.Main;
public class StaticDemo {
static {
main(null);
System.out.println("in static block");
}
public static void main(String args[]){
System.out.println("in main method");
}
}
The output will be...
in main method
in static block
in main method
My expected output is....
in main method
in static block