What is method signature in Java – Does it include return type?

(Last Updated On: April 3, 2018)

What is method signature in java ? – Method signature in java includes only method name and parameters. Method return types are not included in method signature.

For example, in below class method declaration only “foo(String str)” is the method signature that contains method name and parameters. Return type String should in excluded.

 

 

 

NOTE:

Overloaded methods (multiple methods with same name) in a class are also differentiated by the method signatures. Overloading does not include return types.

In below class method examples , two overloaded method by different return types i.e. void and int. This is wrong and compiler will flash an error.

 

 

 

Overloaded methods should be only differentiated by method signatures. For example, below class has two overloaded methods by different method signatures i.e. f() and f(int a).

 

 

Also, note that in java programming, method declaration must contains return types. Method signatures does not include return type.