属性与形参与实参的区别

tra*_*man -3 java

属性与参数和实参有什么区别?这是如何工作的?前任:-

int a = 10;//attribute
method(int a);//argument or parameter
Run Code Online (Sandbox Code Playgroud)

如果我动态传递一个参数,那么它是否会被称为参数或参数。谢谢。

Jim*_*myB 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
  }
}
Run Code Online (Sandbox Code Playgroud)

  • `someAttribute` 就是我所说的 *field* 或 *member*。我相信这也是 JLS 和其他可靠文档中的使用方式。您是否有任何资料来源称它们为广泛使用的“属性”? (2认同)