MENU

Field, Attribute, and Property in Java

2021 年 09 月 13 日 • 阅读: 3985 • 后端

Field

A data member of a class. Unless specified otherwise, a field is not static.

类的数据成员。除非指定,它不是静态的。

举例:

public class Customer {

    // Fields of Customer
    final String field1 = "Fixed Value";
    int name;
}

Attribute

An attribute is another term for a field. It’s typically a public field that can be accessed directly.

Field 的别称,它通常是可以直接访问的 public field,例如数组的长度。(Java SE 术语表中无此定义)

Property

Characteristics of an object that users can set, such as the color of a window.

对象的特征,用户可以设置它,例如窗户的颜色。

举例:

public class Window {

    // Property of Window
    private String color;
  
    public String getColor()
    {
        return this.color;
    }
  
    public void setColor(String color)
    {
        this.color = color;
    }
}

References

TG 大佬群 QQ 大佬群

最后编辑于: 2021 年 09 月 15 日
返回文章列表 文章二维码
本页链接的二维码
打赏二维码
添加新评论

Loading captcha...