#306 – Protected Class Members
April 19, 2011 Leave a comment
Class members marked with the accessibility keyword protected are accessible from within the same class, or from within the code of any classes that derive from the class.
In the picture below, the Dog.DoBark method is marked as protected. The code in any of the blue blocks can call this method.
Code in a subclass of Dog can call the DoBark method.
public class Terrier : Dog { public void TerrierBark() { // CAN call DoBark from subclass this.DoBark(); } }
Code in other classes, not derived from Dog, cannot call the DoBark method.
public class OtherClass { public void DoSomething() { Dog d = new Dog(); // This class CANNOT call DoBark() d.DoBark(); } }