The declaration of x in class b overrides the declaration of x in classa, thus making a.x invisible. If you really want to access a.x, don'tinclude the line public int x; in the declaration for class b.