Monday, December 15, 2008

Method signature and method header

The signature of a method consists of the name of the method and the description (i.e., type, number, and position) of its parameters.

Example:
  • toUpperCase()
  • println(String s)
Note: the names of the parameters have no relevance for the signature

The header of a method consists of the signature plus the description of (the type of) the result.

Example:
  • String toUpperCase()
  • void println(String s)
The keyword void denotes the fact that the method does not return any result (i.e., the method implements an action and not a function).

Two methods of the same class can have the same name, provided they have different signatures. Methods with the same name (but with different signatures) are said to be overloaded. For example, the substring() method in the class String.

No comments: