作者nickboy0211 (Silly Boy)
看板Grad-ProbAsk
標題[理工] 97 台大 計概(程式題)
時間Sun Feb 21 14:51:00 2010
此為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