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!
JigaR Parekh
Ranch Hand
Joined: May 23, 2005
Posts: 112
posted
0
thx for explanation
Smitha Ballikar
Ranch Hand
Joined: Aug 02, 2005
Posts: 99
posted
0
hi,
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.