I was going through the method overloading in java and I was trying the output of the below program in eclipse , the program is ..
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;
}
}
and the output is ..
Output
overloaded method with Type List
overloaded method with Type List
Now in the explanation it was told ..method overloading is resolved at compile time using static binding in Java, so please advise how can I achieve the same through method overriding.