What Is Method Signature In Java

2
39
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

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 
}

}

Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

2 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here