【发布时间】:2013-01-25 20:36:02
【问题描述】:
我正在通过 java 中的方法重载,我正在 eclipse 中尝试以下程序的输出,程序是..
public class OverloadingTest {
public static void main(String args[]){
List abc = new ArrayList();
List bcd = new LinkedList();
ConfusingOverloading co = new ConfusingOverloading();
co.hasDuplicates(abc); //should call to ArryList overloaded method
co.hasDuplicates(bcd); //should call to LinkedList overloaded method
}
}
class ConfusingOverloading{
public boolean hasDuplicates (List collection){
System.out.println("overloaded method with Type List ");
return true;
}
public boolean hasDuplicates (ArrayList collection){
System.out.println("overloaded method with Type ArrayList ");
return true;
}
public boolean hasDuplicates (LinkedList collection){
System.out.println("overloaded method with Type LinkedList ");
return true;
}
}
输出是..
Output
overloaded method with Type List
overloaded method with Type List
现在在解释中被告知..方法重载是在编译时使用 Java 中的静态绑定解决的,所以请告知我如何通过方法覆盖来实现相同的目标。
【问题讨论】:
标签: java