Sunday, May 29, 2011

OOPS Concept-Method Signature


Method Signature

·      In java the method signature is compiled with method name and argument list (the order of arguments also important).
·      Return type is not part of the signature.
·      Compiler uses the method signature to resolve method calls.
·      With in a class two methods having same the signature is not allowed, violation needs to CTE saying method is already defined in class.

Example:
public void m1(int a, int b)
{
m1(int,int); -----> signature of method m1
}

Example:
public void m1(int a, float b)
{
m1(int , float); //valid
m1(float , int);//invalid
}



Example:
class Test
{
public int m1(int i){}//invalid, CTE: m1(int) is already defined in test
public void m1(int i){}
}

No comments: