class Work {
static int num = 3;
public static void main(String[] args) {
Work t = new Work();
t.num = 5;
method(t);
System.out.println(t.num);
System.out.println(num);
}
public static void method(Work t){
t.num = 6;
}
}
因為靜態成員不能直接訪問非靜態成員,你可以這麼寫,不需要傳
class Work {
static int num = 3;
public static void main(String[] args) {
Work t = new Work();
t.num = 5;
t.method();
System.out.println(t.num);
System.out.println(num);
}
public void method(){
t.num = 6;
}
}