Skip to main content
Lesson 7 - More About Methods
ZIPPDF (letter)
Lesson MenuPreviousNext
  
Signature of a Method page 5 of 10

  1. In order to call a method legally, you need to know its name, you need to know how many formal parameters it has, and you need to know the type of each parameter. This information is called the method's signature. The signature of the method doMath can be expressed as as: doMath(int, double). Note that the signature does not include the names of the parameters; in fact, if you just want to use the method, you don't even need to know what the formal parameter names are, so the names are not part of the signature.

  2. Java allows two different methods in the same class to have the same name, provided that their signatures are different. We say that the name of the method is overloaded because it has several different meanings. The computer doesn't get the methods mixed up. It can tell which one you want to call by the number and types of the actual parameters that you provide in the subroutine call statement. You have already seen overloading used in the System.out class. This class includes many different methods named println, for example. These methods all have different signatures, such as:

    println(int)     println(double)     println(String)
    println(char)    println(boolean)    println()
  3. The signature does not include the method's return type. It is illegal to have two methods in the same class that have the same signature but that have different return types. For example, it would be a syntax error for a class to contain two methods defined as:

    double dbl = doMath(int, double);
    int dbl = doMath(int, double);

Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.