Method Signature in Java

method Signature in Java

In the Java method, the signature consists of the method name followed by argument types.

method(int, float)

The return type of the method is not a part of the method signature in Java.

The compiler will use the method signature to resolve method calls.

public class MethodSignature  {
    public void method(){
        System.out.println("Method with one argument");

    }
    public void method(int a, int b){
        System.out.println("Method with two argument");

    }

    public static void main(String[] args) {
        MethodOverloading object = new MethodOverloading();
        object.method();
        object.method(1,2);
    }
}
Method Signature in Java

In a class, more than one method with the same signature is not allowed. if we declare more than one method with the same signature then we will get compile time error- “‘method(int)’ is already defined in ‘MethodSignature'”.

public class MethodSignature {
    public void method(int a){
    }
    public void method(int a){
    }

    }
Method Signature in Java

Similar Java Tutorials

8 thoughts on “Method Signature in Java”

Leave a Comment