Arguments
Arguments are the actual values or data that you pass to a method when calling it.
They are assigned to the corresponding parameters when the method executes.
In short, arguments provide the input that a method needs to work with.
class Example {
void add(int a, int b) {
System.out.println("Sum = " + (a + b));
}
public static void main(String[] args) {
Example obj = new Example();
// 10 and 20 are arguments
obj.add(10, 20);
}
}
Here, 10 and 20 are arguments passed to the method add().
Parameters
Parameters are variables declared inside the method definition.
They act as placeholders to receive the values (arguments) when the method is called.
In simple terms, parameters are like input variables for a method.
class Example {
void add(int a, int b) { // 'a' and 'b' are parameters
System.out.println("Sum = " + (a + b));
}
}
Here, a and b are parameters of the add() method.
Parameters = variables inside the method definition.
Arguments = actual values you pass when calling the method.
Top comments (0)