下面的程序中,为什么出现警告:应该以静态访方式问静态字段?而且出现这个警告程序照样能出结果?

class person3
{
String name;//成员变量,实例变量
static String country="china";//静态的成员变量,类变量
public void show()
{
System.out.println(name+":"+country);
}
}
class staticDemo {

public static void main(String[] args) {
    // TODO 自动生成的方法存根
    person3 p=new person3();
    //p.name="zhangsan";
    //p.show();
    System.out.println(p.country);
    //System.out.println(person3.country)

; }
}

因为是警告,这么写合法,但是编译器怀疑你写错了(主要是怕你忘记country是静态的)
你要将static String country的static去掉
或者 person3.country 代替 p.country
可以消除警告