I understand that this is a very simple question, but it always bothered me. Since I understand things, if you declare a private field in Java, then it is not visible outside of this class. If it is protected, it is available for inherited classes and in only one package (correct me if one of these definitions is incorrect).
Does this mean that it is impossible to declare a field that is accessible only to inherited classes, and not to other not inherited classes in one package?
I appreciate that there are ways around this, but are there any cases where you would like to have this behavior?
Obviously, the above question applies to both methods and fields.
Many thanks.
java encapsulation
chillysapien
source share