Possible Duplicate:
What's the difference between an argument and a parameter?
I was going through some interview questions. I wasn't able to come up with a solid answer to this question:
Difference between arguments and parameters in Java?
How are they different?
This question is related to
java
parameters
arguments
In java, there are two types of parameters, implicit parameters and explicit parameters. Explicit parameters are the arguments passed into a method. The implicit parameter of a method is the instance that the method is called from. Arguments are simply one of the two types of parameters.
They are not. They're exactly the same.
However, some people say that parameters are placeholders in method signatures:
public void doMethod(String s, int i) {
..
}
String s and int i are sometimes said to be parameters. The arguments are the actual values/references:
myClassReference.doMethod("someString", 25);
"someString" and 25 are sometimes said to be the arguments.
There are different points of view. One is they are the same. But in practice, we need to differentiate formal parameters (declarations in the method's header) and actual parameters (values passed at the point of invocation). While phrases "formal parameter" and "actual parameter" are common, "formal argument" and "actual argument" are not used. This is because "argument" is used mainly to denote "actual parameter". As a result, some people insist that "parameter" can denote only "formal parameter".
The term parameter refers to any declaration within the parentheses following the method/function name in a method/function declaration or definition; the term argument refers to any expression within the parentheses of a method/function call. i.e.
Please have a look at the below example for better understanding:
package com.stackoverflow.works;
public class ArithmeticOperations {
public static int add(int x, int y) { //x, y are parameters here
return x + y;
}
public static void main(String[] args) {
int x = 10;
int y = 20;
int sum = add(x, y); //x, y are arguments here
System.out.println("SUM IS: " +sum);
}
}
Thank you!
Source: Stackoverflow.com