First of all it gives the following output:
I think this can be explained like:
When you declare
a with "A a;", you define a object pointer of type A. So whatever this object pointer points is a type of A and considered to be an A. Actually if you try to assign some other object which does not inherent from A, compiler will return an error.
So in the following line, when you assign b to a with "a=b;",
b object is considered to be an instance of A and when you access
x variable, the compiler gets its value from A object.
What do you think?