• Post Reply Bookmark Topic Watch Topic
  • New Topic

BJO - is that any different between argument and parameter ?  RSS feed

 
Nakata kokuyo
Ranch Hand
Posts: 472
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, sometime confuse on the term meaning ...is argument means parameter ? thank you
 
Joe Sondow
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Argument and parameter are different. A parameter consists of a type and a variable name, and it is declared in a method signature to signify that the method expects an argument matching that parameter.

An argument is a value passed to a method.

For example:


The parameter is named p and is of type int. The printOneBigger method expects an argument of that type to be passed to it from some other code. Here is some code that invokes the printOneBigger method using an argument of 6:

 
Jacquie Barker
author
Ranch Hand
Posts: 201
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Couldn't have done better myself! To put it simply:

A parameter is a variable; an argument is a value that we pass in to a parameter.

That being said, folks often use the term "argument" in casual conversation for both: e.g., for the following method:

public void print(String filename) { ... }

it is not uncommon for folks to say "The print method declares one argument, filename, of type String," which is, technically speaking, incorrect; the proper phraseology would be "The print method declares one parameter, filename, of type String" or "The print method takes one argument of type String."

Regards,

Jacquie
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!