Protected access can be tricky. You can only access protected members from within the context of the inherited class. For instance, you can access B's 'i' variable (inherited from A), but not A's through an A reference, since B is in a separate package.
From the JLS:
�6.6.2 Details on protected Access 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.
Hope this helps!
Joined: May 23, 2005
thx for explanation
Joined: Aug 02, 2005
I didnt understand the explanation. Can somebody explain why answer is not 20.
The answer is not 20, as the B class is not allowed access to A's i variable. It's outside the package, and the code that attempts to access the i variable is not responsible for the implementation of the A type.