schrieb:
> If I had not used any access modifier in ClassInPack1 I would have
> package visibility of the members in
> ClassInPack1 and I could understand why test.pack2.Class1Extender
> would not compile
> As it is I have protected access so I would have thought that I could
> extend ClassInPack1 in any
> package and have access to any protected member regardless of package.
> I can get hold of the int but not the Inner class.
> If I change the access modifier of ClassInPack1InnerClass to public
> everything works fine.
> Can anyone explain why this is ?
This is, because it's specified to be
From "The Java Language Specification" (where the term member includes
at least class, interface, field and method):
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.
6.6.2.1 Access to a protected Member
Let C be the class in which a protected member m is declared. Access is
permitted only within the body of a subclass S of C. In addition, if Id
denotes an instance field or instance method, then:
* If the access is by a qualified name Q.Id, where Q is an
ExpressionName, then the access is permitted if and only if the type of
the expression Q is S or a subclass of S.
* If the access is by a field access expression E.Id, where E is a
Primary expression, or by a method invocation expression E.Id(. . .),
where E is a Primary expression, then the access is permitted if and
only if the type of E is S or a subclass of S.
Bye
Michael