Any class B than extends class A inherits A's fields. If the class C extends B , C inherits all infrequent field instances and methods from A and B , i.e. Transitivity is in progress.
If the field is private , then it cannot be directly changed from a subclass; however, you can get around this using the setter / getter methods.
If the field is protected , then the subclass has direct access to it.
EDIT 1:
In a comment, you say that the field is protected , but you still cannot access it from a subclass. The only thing I can think of is that you have this situation:
class A { protected int x; } class B extends A { private int x; } class C extends B { private int z = x; }
It will NOT , because by declaring x again in B , you are hiding the field x from A So now C sees x as B's private variable x , which you do not have access to.
EDIT 2 : I am not going to delete the above edit because it is informative, but now that you have posted your code, it is because your SubClass does not actually extend anything (this was later fixed in the edit).
source share