Header Ads

What Is Method Signature In Java

Understanding method signature is an important aspect of java programing.

The rules are:

  • Method signature consists of name of the method and argument type.
public void method1(float f,int i,char ch)
it's method signature will be method1(float,int,char)
  • In java return type is not a part of method signature.Compiler will always use method signature while resolving method calls. In java in a same class two methods with the same signature not allowed. We will get compile time error.
Class TestTwoMethods{
public static void method1(String st)
{

}
public static void method1(int val)
{
//this is allowed
}
public static int method1(String st)
{

return 0;
//not allowed as both the methods method1 are having same signature 
}

}


Powered by Blogger.