Field, Attribute, and Property in Java
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
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »