METHOD PARAMETERS IN JAVA
Method parameters are used to pass the values in a method. Parameters are specified in the method declaration, and they can allow the method to accept the caller from the arguments.
There are two types of method parameters in Java:
* Formal parameters
* Actual parameters
Syntax:
public void printSum(int num1, int num2)
{
int sum = num1 + num2;
System.out.println("The sum of " + num1 + " and " + num2 + " is " + sum);
}
Example
public class Main
{
static void myMethod(String fname)
{
System.out.println(fname);
}
public static void main(String[] args)
{
myMethod("hardest");
myMethod("longest");
myMethod("simplest");
}
}
Output:
hardest
longest
simplest
.