java main class run method code example
Example 1: main method java
public class Test {
public static void main(String[] args){
System.out.println("Hello World");
}
}
Example 2: run a java class without main method
//This is prior to Java 7
class StaticInitializationBlock{
static{
System.out.println("class without a main method");
System.exit(0);
}
}
Example 3: main method java
public class Test {
static void main(String[] args){
System.out.println("Hello World");
}
}