Well, you are extending
Circle
here, so you have direct access to
z
inside
Test2
. What you can't do is instantiate
Circle
(here you've done it as
c
), and try to access a
protected
field. If you change your code like this
package package2;
import package1.Circle;
public class Test2 extends Circle {
void modifyCircleObjectState()
{
z = 20;
}
}
As you can see, there is no separate
Circle
instance - so when somebody instantiates
Test2
and calls
modifyCircleObjectState
,
z
is updated there.