What is a method signature in Java? -Learn Java
In java, method signature consists of name of the method followed by argument types.
Example:
in java return type is not part of the method signature .Compiler will use method signature
while resolving method calls.
class Demo
{
public void m1(double d){ }
public void m2(int i) { }
public static void main(String args[]){
Demo d=new Demo();
d.m1(11.2);
d.m2(10);
d.m3(); //CE
}
}
CE:cannot find symbol
symbol:method m3(double)
location:class Demo
Within the same class we cant't take 2 method with the same signature otherwise we will
get compile time error.
Example:
public void methodOne() { }
public int methodOne() {
return 10;
}
Output:
Compile time error
methodOne() is already defined in Demo.