Method parameters

The parameter list of a method within parentheses is followed immediately after the method’s name. A method can have zero or more parameters and if a method has zero parameters the parentheses are empty, they cannot be omitted. A method parameter is declared with its data type followed by its name. When the method is called, the values passed to that method needs to be of exactly the same type as in the declaration of the method.

Here are some example method declarations:

In Java it is possible to pass a variable number of parameters to a method. This feature is explained in the section about variable-length (varargs) parameters .

Search for more Java info on this site here:
Custom Search

Please type any questions here.