In this question from whizlabs:
============================
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 c1=new SubCovariantTest();
System.out.println(c1.getObject().x);
}
}
class SubCovariantTest extends CovariantTest{
public B getObject(){
return new B();
}
}
====================================
I understand that variables cannot be overriden.
Here the answer is 5.
But why does c1.getObject() not return B first, and then B.x = 6??
Thanks