Types of Methods in Java
Java methods can be grouped by two things: whether they accept parameters and whether they return a value.
Four Types of Methods
The diagram below gives an overview of all four combinations.

Explanation:
Each method belongs to one type based on its parameters and its return value. The examples below show every type separately.
Example 1: No Parameters, No Return Value
class ShikshaSanchar {
static void showMessage() {
System.out.println("Hello Java");
}
public static void main(String[] args) {
showMessage();
}
}Output:
Hello Java
Explanation:
showMessage() takes no parameters and uses void, so it does not return a value.
Example 2: No Parameters, Returns a Value
class ShikshaSanchar {
static int getNumber() {
return 10;
}
public static void main(String[] args) {
System.out.println(getNumber());
}
}Output:
10
Explanation:
getNumber() takes no input and returns the integer 10.
Example 3: Parameters, No Return Value
class ShikshaSanchar {
static void displayName(String name) {
System.out.println("Name: " + name);
}
public static void main(String[] args) {
displayName("Simran");
}
}Output:
Name: Simran
Explanation:
name is a parameter. The method prints it but returns no value.
Example 4: Parameters, Returns a Value
class ShikshaSanchar {
static int multiply(int a, int b) {
return a * b;
}
public static void main(String[] args) {
System.out.println(multiply(4, 5));
}
}Output:
20
Explanation:
multiply() accepts two parameters and returns their product.
Key Points:
- A method may have parameters, a return value, both, or neither.
- Use
voidwhen a method does not return a value.