The simplest solution is to always return double
in A as it can store every possible int
value.
If you is not an option you need to use an alternative to inheritance.
class C {
public A getA();
public B getB();
}
C c = new C();
int a = c.getA().foo();
double b = c.getB().foo();