I don't understand the connect or the difference between parameters and arguments. Can you use either as a method? How do you return an argument? Any help is greatly appreciated.
-
1While not terribly well asked, I think it's a reasonable question and something a lot of people don't understand. – Jon Skeet Jul 25 '15 at 09:37
-
2Hmmm ... I would vote to close this as a duplicate for ["What's the difference between an argument and a parameter?"](http://stackoverflow.com/questions/156767/whats-the-difference-between-an-argument-and-a-parameter). Although this has the C# tag, the concept is independent of any language. – Seelenvirtuose Jul 25 '15 at 10:05
-
That is very good beginner (and not only) question. I remember struggling with it when I start learning programming since these terms ware used interchangeably, until someone finally said hat: "*parameter* stores *argument* passed to method". So you can see parameter as *variable*, and argument is *value* passed to method. – Pshemo Jul 25 '15 at 11:27
-
It could also be a duplicate of [Difference between arguments and parameters in Java](http://stackoverflow.com/q/12709026). Well at the end, someone here hasn't spend much time for research :(. – Tom Jul 25 '15 at 11:28
1 Answers
Warning: a lot of people don't differentiate between "parameter" and "argument". They should, but they don't - so you may well see a lot of pages with incorrect uses of the terms.
When you declare a method or constructor, the parameters are the bits you put in declarations to receive values to work with. For example:
public void foo(int x, int y)
Here x
and y
are the parameters. Within the method, they just act like local variables.
When you call a method or constructor, the arguments are the values that you pass in. Those act as the initial values of the parameters. So for example:
foo(5, 3);
Here 5 and 3 are the arguments - so the parameter x
will start with a value of 5, and the parameter y
will start with a value of 3. Of course, you can use a parameter (or any other variable) as an argument too. For example:
public void foo(int x, int y) {
System.out.println(y);
}
Here y
is a parameter in the foo
method, but its value is being used as the argument to the println
method.
Can you use either as a method?
No, they're a completely different concept.
How do you return an argument?
Again, that doesn't really make sense. You can use the value of a parameter in a return statement though:
public int foo(int x, int y) {
// Normally you'd use y for something, of course
return x;
}

- 1,421,763
- 867
- 9,128
- 9,194