tags:

views:

96

answers:

3

Possible Duplicate:
Private and Protected Members : C++

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

+2  A: 

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
+4  A: 

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
+1 for pretty formatting
Brian R. Bondy
A: 

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
This question was tagged c++ though
Gareth
Important details like that belong in the question, not just the tags.
Ben Voigt