Re: [問題]有關private屬性
※ 引述《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)
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 8 篇):