Re: [問題]有關private屬性

看板java作者 (Alien)時間18年前 (2007/07/20 19:44), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/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 可以被使用,但是其他的類別無法使用 : 想請教各位高手 我這樣的說法是對的嗎? : 煩請解答了 你的 main() 是屬於 class test 底下的, 即是說是 class test 的 static method. private 是可以被 "同一個 class" 存取 所以 class test 的 static method 可以 存取一個 class test 的 instance 的 private members. alien -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 202.22.246.26 ※ 編輯: adrianshum 來自: 218.102.121.195 (07/20 23:46)
文章代碼(AID): #16eA0qDf (java)
討論串 (同標題文章)
文章代碼(AID): #16eA0qDf (java)