You mean: This gives a compile error in the method process(A a) in class B.
This is one of the peculiarities of how 'protected' works. When a field is 'protected', it is visible in subclasses and in classes of the same package; but only the field of the object itself is visible. In this example, you are looking at field 'i' of a
different object - and then it's not visible.
Section 6.6.2 of The
Java Language Specification explains this (with just a very short sentence):
A protected member or constructor of an object may be accessed from outside the package in which it is declared only by code that is responsible for the implementation of that object.
Note: Please
use code tags when you post source code.