[問題] SCJP練習題

看板java作者 (You Are The One!!)時間18年前 (2008/01/07 21:45), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/2 (看更多)
public class Test{ public int aMethod(){ static int i = 0; i++; return i; } public static void main(String args[]){ Test test = new Test(); test.aMethod(); int j = test.aMethod(); System.out.println(j); } } 請問一下是錯在哪阿? 我看解答是i一定要是final(當然沒有i++)這樣就可以了,why? 懇請各位高手指導 感謝~~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.216.44.240

01/08 12:18, , 1F
在method的變數是loacl variable, so我覺得應該要加~
01/08 12:18, 1F
文章代碼(AID): #17WYqFXq (java)
討論串 (同標題文章)
文章代碼(AID): #17WYqFXq (java)