how to write a method inside main in java code example

Example 1: java define main function

public class Program {
  public static void main(String[] args){
    System.out.println("Hello, World!");
  }
}

Example 2: main method java

public class Test {

public static void main(String[] args){

	System.out.println("Hello World");
	
}
}

Example 3: java main method

public static void main(String args[]){}

Example 4: main methode java

public class Test {

public static void main(String[] args){

	System.out.println("Hello Luggas");
	
	}
}

Example 5: main method java

public class Test {

static void main(String[] args){

	System.out.println("Hello World");
	
}
}

Example 6: how to write a method inside main in java

public class Main {
  static void myMethod() {
    System.out.println("I just got executed!");
  }

  public static void main(String[] args) {
    myMethod();
  }
}

// Outputs "I just got executed!"

Tags:

Java Example