Protected access specifier allows a child class to access the member variables and member functions of its base class. This way it helps in implementing inheritance. We will discuss this in more detail in the inheritance chapter.
The following is an example showing we have set an protected member variable in Class A.
class A {
protected int a2 = 87;
}
Now under the derived class when we will try to access the above variable from the derived class object, then it would work fine as shown below −
Example
using System;
class A {
protected int a2 = 87;
}
class B : A {
static void Main() {
A a = new A();
B b = new B();
b.a2 = 10;
}
}