A method signature is part of the method declaration. It is the combination of the method name and the parameter list.
The reason for the emphasis on just the method name and parameter list is because of overloading. It's the ability to write methods that have the same name but accept different parameters. The Java compiler is able to discern the difference between the methods through their method signatures.
Examples:
public void setEmpReference(int xCoordinate, int yCoordinate)The method signature is setEmpReference(int, int) – i.e., the method name and the parameter list of two integers. The Java compiler will let us add another method like so:
{
//method code
}
public void setEmpReference(Point position)because it's method signature is different – setEmpReference(Point).
{
//method code
}
No comments:
Post a Comment