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.

Four types of Java methods based on parameters and return values

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 void when a method does not return a value.

Welcome to ShikshaSanchar!

ShikshaSanchar is a simple and helpful learning platform made for students who feel stressed by exams, assignments, or confusing topics. Here, you can study with clarity and confidence.

Here, learning is made simple. Notes are written in easy English, filled with clear theory, code examples, outputs, and real-life explanations — designed especially for students like you who want to understand, not just memorize.

Whether you’re from school, college, or someone learning out of curiosity — this site is for you. We’re here to help you in your exams, daily studies, and even to build a strong base for your future.

Each note on this platform is carefully prepared to suit all levels — beginner to advanced. You’ll find topics explained step by step, just like a good teacher would do in class. And the best part? You can study at your pace, anytime, anywhere.

Happy Learning! – Team ShikshaSanchar