A class inherits from its direct superclass and direct superinterfaces all the non-private fields of the superclass and superinterfaces that are both accessible to code in the class and not hidden by a declaration in the class.
Your code wont compile, if you place both the classes in the same file. Because there can be one and only public class per source file.
Anyways if you remove public from the class A, the description would be as following:
Until you declare static member as private, it is accessible by the subclasses. There is only one copy of the myX so if the subclass method increments myX it increments the class variable myX. If the class is public and member variable is also public and static as well in your case, it is accessible by the world, even you dont require the instance of the class to access the static member variable.
I think your confusion runs around polymorphic behavior, which can not be achieved if method of the super class is static. No run time polymorphism.
Thanks and Regards, cmbhatt
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database