static有点搞不清楚,是不是static修饰的变量只能赋一个值?再赋值的话会把原来的值给覆盖? Demo {
public static void main(String[] args) {
Person p1 = new Person();
p1.name = “麦克”;
p1.country = "美国";
Person p2 = new Person();
p2.name = "红杉";
p2.country = "韩国";
p1.speak();
p2.speak();
}
}
class Person {
String name;
static String country = 中国;
public void speak() {
System.out.println(name + "..." + country);
}
}
|