看板 Grad-ProbAsk 關於我們 聯絡資訊
此為java的inheritance觀念的題目,曾有試著自己key到電腦去run。 但一直compile錯誤,目前也沒時間debug了,希望會的大大能幫忙。謝謝。 Given the java code fragment in the follow a. what is the output of the program, while executing the "java Main" command? 程式如下: public class A{ public void m1(){ System.out.println("123"); } } public class B extends A{ public void m1(){ System.out.println("456"); } } public class Main{ public void main(String[] args){ A ref = new B(); <-----希望能解釋一下這一行,因new b 卻用a的型態??? ref.m1(); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.118.242.16 ※ 編輯: nickboy0211 來自: 140.118.242.16 (02/21 15:08)
gdgdgdg:456 ? 02/21 15:19
gdgdgdg:很濫的解釋 ==>> 小的資料 能夠放到大的容器當中 02/21 15:37
zeowo:標題錯誤 02/21 17:01