Does a method’s signature in Java include its return type?

Quoting from Oracle Docs:

Definition: Two of the components of a method declaration comprise the method signature—the method’s name and the parameter types.

enter image description here

Since the question was edited to include this example:

public class Foo {
    public int  myMethod(int param) {}
    public char myMethod(int param) {}
}

No, the compiler won’t know the difference, as their signature: myMethod(int param) is the same. The second line:

    public char myMethod(int param) {}

will give you can error: method is already defined in class, which further confirms the above statement.

Leave a Comment