Java abstract method with abstract parameter and inheritance
I recently fumbled into a problem with an API and an implementation where the following type of code appeared: The API is an abstract class: public abstract class A { public A sum(A a) { System.out.println("A.sum(A) called"); return null; } } The implementation is a simple class: public class B extends A { public B sum(B b) { System.out.println("B.sum(B) called"); return null; } } When it comes to using it I write: public class Main { public static void main(String args[]) { B b = new B(); A basa = new B(); b.sum(b); basa.sum(b); basa.sum(basa); } } Which results in: % java Main B.sum(B)