|
Do you need help with your Java programming?
Click here for instant help with your Java code. |
Method Parameters in Java
The parameter list of a method is followed within parentheses 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: |
//This method takes no parameters public void methodWithoutParameters() { } //This method takes one parameter of type int public void methodWithIntegerParameter(int i) { } //This method takes two parameters of type String public void methodWithTwoStringParameters(String s1, String s2) { } |
In Java it is possible to pass a variable number of parameters to a method. This feature is explained on the next page. |
| Previous | Next | |
Tutorial Home | ||
| Do you know your Java? | |
| Take a Ten-Question-Java-Quiz! | |
Search for code examples on this site
