Call methods

After defining a method in Java, it can be called using the method name.

Code Explanation

LineDescription
3Defines the method print(). It’s a static, private (The method cannot be accessed outside the class) method.
The return value of the method is of type void, so there is no return value
4Outputs the string “Test method”
7Defines the main function
8 – 9Calls the print() method
class MethodCall {

	private static void print() {
		System.out.println("Test method");
	}

	public static void main(String[] args) {
		print();
		print();
	}
}
Output
Test method
Test method