public class CovariantTest { public A getObj() { return new A(); } public static void main(String[] args) { CovariantTest c = new SubCov
Replace your A and B above with:
class A { public int getX() { return 5; } } class B extends A { public int getX() { return 6; } }
That will probably answer your question about what is wrong ;-)