本文共 1226 字,大约阅读时间需要 4 分钟。
1 class Demo{ 2 public static void main(String[] args) 3 { 4 Person p = new Person(); 5 System.out.println(p.country); //1、新建对象调用 6 System.out.println(Person.country); //2、通过类名直接调用 7 } 8 } 9 class Person{ 10 static String country = "china"; 11 } |
class Demo{ public static void main(String[] args) { Person.show(); } } class Person{ static String country = "china"; String name = "jinfulin"; public static void show() { System.out.print(country); //正确 //System.out.print(name); //错误 } } |
转载地址:http://dbgma.baihongyu.com/