Java Covariants
<pre><code>public class CovariantTest {
    public A getObj() {
        return new A();
    }

    public static void main(String[] args) {
        CovariantTest c = new SubCovariantTest();
        System.out.println(c.getObj().x);
    }
}

class SubCovariantTest extends CovariantTest {
    public B getObj() {
        return new B();
    }
}

class A {
    int x = 5;
}

class B extends A {
    int x = 6;
}
</code></pre>

<p>The above code prints 5 when compiled and run. It uses the covariant return for the over-ridden method. </p>

<p>Why does it prints 5 instead of 6, as it executes the over ridden method getObj in class SubCovariantTest. </p>

<p>Can some one throw some light on this. Thanks.</p>
