Since B extends A then B (even though it does not inherit x) has a copy of x.
x is private, therefore it can only be accessed within its class (in this case A).
The parameter in the second getX() is of type B and is located inside A, then why can't I access x directly?
Welcome again Please indent your code; you are dealing with a PC screen with about 50 lines of text, not some little 2½″ screen on a phone. So there is no need to try to squash a method into one line. I shall try copying your code with correct indentation and you can see how much better it will look
I realize this is just experimental code but you should never have a reference to a subclass in a superclass. That is, your reference to class B on line 5 is a huge red flag that indicates a serious design flaw.
Yes, this is experimental. I want to understand the nature of access modifiers and inheritance.
b.x generates error because x, since not inherited, is not a member of B even though a copy of x exists in a B object. Right?
Also, when I try ((A) b).x then the program works fine! Is it because x is a member of A and the return statement is inside the class A?
Also if I have,
Why the error (i.e. x has protected access in beautifulworld.Parent)?
I know that a protected member can be accessed inside its class, other classes in the same package, and subclasses.
What is wrong with my understanding?
I'm all for learning about the limits of a language and all but I don't see any particular use in the way you're approaching this exploration of scope and visibility in Java. These things you are trying are not things you would do in normal programming situations. It's like trying to see if you can kick your head. Sure, with enough effort you may be able to do it but you have to ask yourself "Why would you want to do that?"