Re: [問題]有關private屬性

看板java作者 (愚人)時間18年前 (2007/07/20 19:02), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串2/8 (看更多)
※ 引述《mixfuture (恩)》之銘言: : class test{ : private int n = 7; : public static void main(String [] args) : { : test a = new test(); : System.out.println(a.n); : } : } : 我是JAVA新手.想要請教各位 : 為什麼 a.n 可以被列印出來.他不是屬於private的嗎... : 還是說再同一個類別裡面 private 可以被使用,但是其他的類別無法使用 : 想請教各位高手 我這樣的說法是對的嗎? : 煩請解答了 class test{ <== private start at here and born private int n; public void fooMethod(){ // in private realm XD private int m; <-- born } // m out of scope --> die } <== private end at here and die -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.128.219.202 ※ 編輯: qrtt1 來自: 220.128.219.202 (07/20 19:02) ※ 編輯: qrtt1 來自: 220.128.219.202 (07/20 19:03)
文章代碼(AID): #16e9OxIA (java)
討論串 (同標題文章)
文章代碼(AID): #16e9OxIA (java)