Thursday, May 21, 2020

What Is Method Signature in Java

In Java, a method signature is part of the method declaration. Its 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. Its 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. Method Signature Examples public void setMapReference(int xCoordinate, int yCoordinate){//method code} The method signature in the above example is setMapReference(int, int). In other words, its the method name and the parameter list of two integers.   public void setMapReference(Point position){//method code} The Java compiler will let us add another method like the above example because  its method signature is different, setMapReference(Point) in this case. public double calculateAnswer(double wingSpan, int numberOfEngines, double length, double grossTons) {    //method code} In our last example of a Java method signature, if you follow the same rules as the first two examples, you can see that the method signature here is  calculateAnswer(double, int, double, double).

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.