在类标识符的上下文中,语句具有以下解释的含义: 首先private
和public
关键字是访问符号,这意味着所有具有private
关键字的成员仅在它们声明的类的范围内可见。所有public
关键字的成员是类的范围之外可见。
如
class foo{
public int myVar;
private int myBar;
}
现在,如果你实例化'富”
foo f = new foo();
f.myVar // is valid
f.myBar // is invalid and generates compile time error.
static
关键字表示该标识符的分配是类的所有实例常见,所以这个标识的,在分配编译器第一次遇到类型定义的时间。因为,对于任何类类型分配只发生一次,只有一个保持静态字段,它可以跨越这个类的所有对象进行访问的实例。
final
关键字表示(在标识符的上下文中),这些标识符可被初始化一次,然后被关闭任何修改。 (在方法方面它意味着该方法不能由派生类中重写)。
现在回到你的问题,下面的语句将意味着:
private static final int a;
// 'a' has scope local to the class and its value is accessible through Type
// and shared across all instances of that type and its value cannot be
// changed once initialised.
private static int b;
// 'b' has scope local to the class and its value is accessible through Type
// and shared across all instances of that type.
private final int c;
// 'c' has scope local to the class and its value cannot be changed once
// initialised.
private int d;
// 'd' has scope local to the class
public static final int e;
// 'e' has scope beyond the class, it can be accessed outside the class
// through an instance of this class and its value is accessible through
// Type and shared across all instances of that type
// and its value cannot be changed once initialised.
public static int f;
// 'f' has scope beyond the class, it can be accessed outside the class and
// value is accessible through Type and shared across all instances of that
// type
public final int g;
// 'g' has scope beyond the class, it can be accessed outside the class
// through an instance of this class
// and its value cannot be changed once initialised.
public int h;
// 'h' has scope beyond the class, it can be accessed outside the class
// through an instance of this class
干杯!
'private'表示它对这个类是私人的,并且不在那个类之外访问。 –