看板 java 關於我們 聯絡資訊
: 0 : 是因為Base的default constructor都會把member attribute都設成0嗎? 應該說 int 如果沒給起始值,會自動給 0 . : 還有如果我不加入那個showData() : 錯的原因是因為這種Heterogeneous機制 : Base a_base=new Derive(); : a_base只能呼叫Base裡面的method嗎? 因為它把a_base當成 Base類別的 instance, 所以他只能使用Base類別裡的method, 它的可見範圍就只有Base和 super class (Object) 裡面的東西。 不過你也可以透過轉型的方式使用啦, 適不適用只端看你的使用需求。 Base a_base; a_base=new Derive(); ((Derive)a_base).showData(); 這樣就不需要加上showData在Base內了 -- I am a person, and I am always thinking . Thinking in love , Thinking in life , Thinking in why , Thinking in worth. I can't believe any of what , I am just thinking then thinking , but worst of all , most of mine is thinking not actioning... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.134.27.68