When a Java method executes a Java file, the main method is automatically executed. The main method gives instructions to each method, and each method performs its own processing. Execute Main.java => main method => Each method (method 1) (method 2) (method 3) and so on. Method definition
Main.java
public static void method name() {
Process to be executed;
}
[Example]
Main.java
class Main { //Main class block
public static void main(String[] args) { //main method is called
hello(); //The hello method is called inside the main method
}
public static void hello() { //Good morning is executed in the hello method
System.out.println("Good morning");
}
} //Main class block
Recommended Posts