class A{
int x= 5;
}
class B extends A{
int x =6;
}
public class CovariantTest
{
public A getobject(){
return new A();
}
public static void main(
String[] args)
{
CovariantTest c = new SubCovariant();
System.out.println(c.getobject().x);
}
}
class SubCovariant extends CovariantTest{
public B getobject(){
return new B();
}
}
Answer is 5.
please explain this answer.when c.getobject() is called, at runtime ,it will select the SubCovariant class method and since it returns B's object,we should get the answer as B.x = 6 right.if i am wrong please correct me.