Hello sandra Bachan , this is the most frequent mistake encountered by
JAVA learners.
Just to follow one rule :
Non-Static members cannot be accessed from Static context ie Static methods directly without referring to any object.
Reasoning :- Static members could exist before object creation.
So when you are trying to access variable x which is inherited from the parent class, it is still non- static. You try to access a non-static variable from the static main method and hence the error. Because at that time if suppose,say, 100 objects of the child class already exists on the heap, then compiler complains because it does not resolve that whose x are you trying to refer .
But But But if you say i am referring to object number ,say 75, then you would say ob75.x , now compiler knows that you are referring to x which exists inside object75, and hence it is allowed.