Static fields are not inherited, they do not override each other, they are shadow of each other. When directly accessing a static field with the same name in your case, the superclass field hides another field, and you have two int Xes, but one of the superclass is not hidden and will not be selected. Even better, when you call another instance of the same method and access the same static field, that is, when things get very strange. Static fields are combined together and you can end up with X being 5 + 5 = 10.
On the other hand, if you inherit a non-stationary field from a superclass, there is no problem with its different value in the subclass, because the subclass can override the non-static super member.
Static variables and inheritance are bad, it breaks polymorphism, where you least expect it. (In fact, if you understand the concepts of your language, you expect this, but other people cannot)
source share