Hi,
There are several questions in our question bank that touch upon this aspect. Explanations for these questions such as Qid 2.966, explain how protected works.
Members with default accessibility are only accessible within the class itself and from classes in the same package.
Protected members are in addition accessible from subclasses. Members with private accessibility are only accessible within the class itself.
Explanation to question with Qid 2.978 says,
public > protected > package (i.e. no modifier) > private
where public is least restrictive and private is most restrictive.
Remember:
protected is less restrictive than package access. So a method(or field) declared as protected will be accessible from a subclass even if the subclass is not in the same package.
The same is not true for package access.
A top level class can only have either ///public/// or no access modifier but a method or field can have all the four. Note that ///static///, ///final///, ///native/// and ///synchronized/// are not considered as access modifiers.
Explanation to qid 2.1217 says,
'protected' means the method will be accessible to all the classes in the same package and all the subclasses (even if the subclass is in a different package).
I was alarmed by your claim that no book makes this clear so I looked for this in a
very popular certification book and while explaining default and protected access on page 33 it clearly says,
The protected and default access control levels are almost identical, but with one
critical difference. A default member may be accessed only if the class accessing the
member belongs to the same package, whereas a protected member can be accessed
(through inheritance) by a subclass even if the subclass is in a different package.
...
Default and protected behavior differ only when we talk about subclasses. If the
protected keyword is used to define a member, any subclass of the class declaring
the member can access it through inheritance. It doesn't matter if the superclass and
subclass are in different packages, the protected superclass member is still visible to
the subclass (although visible only in a very specific way as we'll see a little later).
This is in contrast to the default behavior, which doesn't allow a subclass to access a
superclass member unless the subclass is in the same package as the superclass.
...
But when you think protected, think package + kids. A class with a
protected member is marking that member as having package-level access for all
classes, but with a special exception for subclasses outside the package.
I have not investigated your claim thoroughly using other books but I am confident that any book rated 4+ stars would have included this information with good clarity.
HTH,
Paul.