class Person{ private String name="haha"; private int age; private static String country="CN"; Person(String name,int age){ this.name=name; this.age=age; } { System.out.println(name+".."+age); } public void setName(String name){ this.name=name; } public void speak(){ System.out.println(this.name+".."+this.age); } public static void showCountry(){ System.out.println("country="+country); } } class PersonDemo{ public static void main(String[] args){ Person p=new Person("zhangsan",20); } } 输出结果是 haha..0, 上面的 private String name="haha"; private int age; 改为 String name="haha"; int age; 结果会怎么样呢?还是 haha..0 |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |