After defining a method in Java, it can be called using the method name.
Line | Description |
---|---|
3 | Defines 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 |
4 | Outputs the string “Test method” |
7 | Defines the main function |
8 – 9 | Calls the print() method |
class MethodCall {
private static void print() {
System.out.println("Test method");
}
public static void main(String[] args) {
print();
print();
}
}
Test method
Test method