What is the goal from using "protected"? [duplicate]
Possible Duplicate:
Private and Protected Members : C++
Why use the keyword "protected"? What does it mean?
Technically it means:
Members marked as protected are visible to the owning class and classes derive from the owning class.
In Context:
P
r
o
P t p
u e r
b c v
l t a
i e t
c d e
===========
Y N N Accesses by global function
Y N N Accessed by a member of another class
Y Y N Accessed by a member of derived class
Y Y Y Accessed by a member of the same class
protected
is similar to private
in that classes and code external to our class cannot access these members of our class.
The difference is that protected
members can be accessed by classes that derive from ours, while private
members can't.
Protected is an access level modifier that can be applied to members of classes in Java. The list of access level modifiers in order of least to most restrictive are public, protected, package (no modifier), or private.
The protected modifier allows any child classes to access the member.
精彩评论