鉴于:
public class Base {
public static final String FOO = "foo";
public static void main(String[] args) {
Base b = new Base();
Sub s = new Sub();
System.out.print(Base.FOO); // <- foo
System.out.print(Sub.FOO); // <- bar
System.out.print(b.FOO); // <- foo
System.out.print(s.FOO); // <- bar
System.out.print(((Base)s).FOO); // <- foo
}
}
class Sub extends Base {
public static final String FOO="bar";
}
我的疑问是,在第 8 行和第 9 行中,我们使用引用变量来访问类的静态成员......这可能吗?因为静态成员只能通过类名访问......请纠正我哪里错了?