该程序运行结果:
原因:
new Homework08().count1();
中改变的count的值是该对象的count变量,
但是Homework08 t1 = new Homework08(); t1.count2(); t1.count2();
改变的都是t1变量的count的值
//20224.07.16
public class Homework08 {
public static void main(String[] args) {
new Homework08().count1();
Homework08 t1 = new Homework08();
t1.count2();
t1.count2();
}
int count = 9;
public void count1(){
count = 10;
System.out.println("count1=" + count);
}
public void count2(){
System.out.println("count1=" + count++);
}
}