From the developer guides we have the following definition:
This means that the method or variable is visible to any inner classes in the defining Apex class, and to the classes that extend the defining Apex class. You can only use this access modifier for instance methods and member variables. Note that it is strictly more permissive than the default (private) setting, just like Java.
However, I am still unsure when to use this and how it differs from the public modifier.
Best Answer
The
protected
access modifier is much more likeprivate
thanpublic
. In fact, for a class which is notvirtual
norabstract
, this access modifier would be the same as private (though it's not allowed). However, once you allow extension of the class, you can then see it in overriding implementations.