Protected Access Modifier in C# with Example

Protected Access Modifier in C# with Example
Rating: 5 - 1 Votes

Protected Access Modifier in C# with Example

C#In inheritance in C#, we know that all the public type members in base class are accessible through derived class.  Private type members in base class cannot be accessed through derived class.  Apart from Public and Private access modifiers, there is another access modifier called Protected access modifier.  By using Protected access modifier, you can access a protected type member in base class through its derived class only.

There are 3 ways to access protected type member.

  1. Create instance of derived class and access the member.
  2. Use base keyword.
  3. Use this keyword.

Example is given below for all 3 solutions.

 Output:

Method 1
Method 2
Method 3
Press any key to continue . . .