need a explanation!
I came accross a scjp MCQ that is,
class A{
int x=10;
void method(){
System.out.println("A prints"+x);
}
}
class Bextends A{
int x=20;
void method(){
System.out.println("B prints "+x);
}
}
class c{
publicstaticvoid main(String args[]){
A y=new B();
y.method();//Line P
System.out.println(y.x);//Line Q
}
}
When i compile the code it will give the output as "B prints 20" and "10". But i am bit confuse how come the "Line P" access the "x" in class B and "Line Q" access the variable in class A instead of class B.Can anyone give me a explanation how this happened and what realy happens in this code.

