Before start I have small code to understand question much better.
public interface Shape {
public void draw();
}
public class Circle implements Shape {
@Override
public void draw() {
System.out.println("Drwaing circle");
}
public void kill() {
System.out.println("Class specific Method");
}
public static void main(String[] args) {
Circle C = new Circle();
C.draw(); //Compiled
C.kill(); //Compiled
Shape S = new Circle();
S.draw(); //Compiled
S.kill(); //Not able to Compile
}
}
As you can see, If I use Interface type object to call class(Circle) method(kill), I am not allowed. It makes sense because kill method neither defined in interface nor implemented.
My question is if that's a case, When we use List in a manner mentioned below, then why its always said that List uses ArrayList methods...? Technically It should not according to my above example.
List myList = new ArrayList();
If not, then Whose methods List use..? Because List defined methods need to be implemented somewhere in class which implements List. No..?
Check first comment in the answer in below link as well, it also says the same thing. What is the difference between List and ArrayList?
Is anyone Can come up with more clear picture, how its working ? Whose methods List uses while above kind snippet..?