How can run a Java program without main method?


Use a static block to run java program without using main method.

static block execute before of main method, and use System.exit(0); to terminate the java program.

I have write a java program without using main method.



package er.android;
public class Logic {
 
 static 
 {
  System.out.print("Welcome to the www.er-android.blogspot.in");
  System.exit(0);
 } 

}


In Java 7 or Higher, this does not work anymore, even though it error: Error: Could not find or load main class Logic




0 comments:

Post a Comment

Previous Newer Post