-2

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.

6
  • 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". Commented May 7, 2015 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. Commented May 7, 2015 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. Commented May 7, 2015 at 13:03
  • parameter and argument are used interchangeably .And attribute , you can call, a piece of information about containing entity . Commented May 7, 2015 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. Commented May 7, 2015 at 13:04

2 Answers 2

4
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
  }
}
Sign up to request clarification or add additional context in comments.

4 Comments

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?
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.
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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.