我正在经历所述方法在Java重载和我试图在eclipse以下程序的输出,该程序是..关于方法在Java重载
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中解决,所以请告诉我如何通过方法重写来实现相同。