In Java, we have four access specifiers: public
, protected
, package-private (default), and private
. This is well known and not an issue for me.
My question is with regard to the naming of protected
. As shown in the table here, giving a field the default access specifier of package-private prevents subclasses outside of the package from using it, but applying the keyword protected
doesn't actually protect it – on the contrary, it opens it up to subclasses of any package.
So, why doesn't protected
protect things; why is it less restrictive than no modifier at all?