作者FatDevil (You Are The One!!)
站內java
標題[問題] 不定長度引數的overloading問題
時間Mon Apr 7 20:35:58 2008
import static java.lang.System.out;
class Father{
public void foo(String...a){
out.println("Father.foo");
}
}
class Son extends Father{
public void foo(String a){
out.println("Son.foo");
}
}
public class app2{
public static void main(String args[]){
Father f = new Son();
f.foo("test");
}
}
請教各位:
當我在一個引數的情形下怎麼知道他會去呼叫father 還是 son的foo()?
因為一但我把father class 的foo method改成public void foo(String a)
在多型下他會去呼叫son class 的foo() (overriding沒錯吧)
可是在foo(String...a)和foo(String a)
情形下怎麼知道他會去呼叫哪一個?
感謝``
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.136.175.118
1F:→ FatDevil:我知道結果是father class 但是不知道為什麼 04/07 20:36
2F:推 H45:String... 某種程度上是陣列,String 是一個字串,有差 04/07 20:38
3F:推 TonyQ:奇怪 我記得我發過一篇關於多重引數的介紹 = =;;找不到 04/07 21:55
5F:→ FatDevil:感謝T大 我找到了 搜尋"多重"才有 04/07 22:23
6F:推 wctang:不甜的 syntax candy @@ 04/07 23:02