摘要:靜態變數與區域變數
public class HelloWorld {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Test t1 = new Test();
t1.i=2;
t1.SiInc(); //這裡會讓Test.si變成3
System.out.println(Test.si);
Test t2 = new Test();
t2.i=3;
t2.SiInc(); //這裡會讓Test.si變成6
System.out.println(Test.si);
}
}
public class Test {
int i = 0;
static int si = 1;
public void SiInc() {
si += i;
}
}