-3

What is the difference between attribute and parameter and argument? And how does this works? ex:-

int a = 10;//attribute
method(int a);//argument or parameter

And if i pass a argument dynamically then whether it will be called parameter or argument. thanks.

singhakash
  • 7,891
  • 6
  • 31
  • 65
  • 1
    The second line of your code wouldn't even compile. The first line is unclear in terms of whether you're declaring an instance field or a local variable - both of which are more standard Java terminology than "attribute". – Jon Skeet May 07 '15 at 13:03
  • 1
    Attribute is what you put on top, argument is what you pass from a caller viewpoint, parameter is what's passed from a callee viewpoint. That, and java calls it annotations rather than attributes. – Jeroen Vannevel May 07 '15 at 13:03
  • 1
    "Attributes" = those "variables" declared outside a method in a class, a.k.a. "fields"; "parameters" = types+names of the input values a method expects; "arguments" = values given to a method as it's ->parameters when the method is called. – JimmyB May 07 '15 at 13:03
  • parameter and argument are used interchangeably .And attribute , you can call, a piece of information about containing entity . – Alok Mishra May 07 '15 at 13:03
  • 1
    @AlokMishra: *You* may use parameter and argument interchangably, but they're quite distinct terms, and I think it's worth *trying* to use them properly. – Jon Skeet May 07 '15 at 13:04
  • Fair enough @Albert, I've deleted my remark :) (Will remove this one soon too) – CubeJockey May 07 '15 at 14:14

2 Answers2

5
class SomeClass {

  private int someAttribute; // <-- Attribute (declaration)

  public void setSomeAttribute( int attrValue /* <-- Parameter (declaration) */ ) {
    int twice = attrValue * 2; // (local) variable
    this.someAttribute = twice;
  }

  public void doSomethingElse() {
    int x; // (local) variable
    x = 1;
    setSomeAttribute(x); // the value of x is the argument
    setSomeAttribute(999); // 999 is the argument
  }
}
JimmyB
  • 12,101
  • 2
  • 28
  • 44
  • 1
    `someAttribute` is what I would call a *field* or *member*. I believe this is also how it's used in the JLS and other reliable documents. Do you have any source that calls them "attributes" in widespread usage? – Jeroen Vannevel May 07 '15 at 13:12
  • http://en.wikipedia.org/wiki/Class_%28computer_programming%29#Structure – JimmyB May 07 '15 at 13:25
  • You can't assume specific terminology from such a general document. It specifies "Properties" and "Attributes" as synonyms of fields. In C#, for example, these are 3 very distinct class members. – Jeroen Vannevel May 07 '15 at 13:27
  • 1
    http://en.wikipedia.org/wiki/Class_diagram#Members – JimmyB May 07 '15 at 13:29
3

A Parameter is what appears in the definition of the method. An Argument is the instance or primitives passed to the method during runtime.

Alok Mishra
  • 926
  • 13
  • 39