-1

Possible Duplicate:
Private and Protected Members : C++

Why use the keyword "protected"? What does it mean?

Community
  • 1
  • 1
roger
  • 11

3 Answers3

4

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
Martin York
  • 257,169
  • 86
  • 333
  • 562
2

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.

Matthew Scharley
  • 127,823
  • 52
  • 194
  • 222
0

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.

Sanjay
  • 156
  • 1
  • 3