EDIT: changed methodA to someMethod everywhere
In this tutorial, an interface has been defined like this:
public interface MyInterface{
public int someMethod();
public class ClassA implements MyInterface{
@Override
public int someMethod(){
//codeA
}
}
public class ClassB implements MyInterface{
@Override
public int someMethod(){
//codeB
}
}
}
Then they have passed an instance of the above interface in a method of another class like so:
public class MyAnimationClass{
static void animate(final MyInterface myInterface){
myInterface.someMethod();
}
}
How does this instantiation of an interface work? Moreover, in the statement myInterface.someMethod();
, someMethod()
of which class would be called by default - ClassA or ClassB?