Example Program for Access Modifiers in C#

This tutorial demonstrates the use of Access Specifiers in C# shows the accessing of different specifiers present in C# with source code. You may go through the theory of access modifiers in C#.

Question:
Write a C# program to Illustrate the Use of Access Specifiers


Example Program for Access Modifiers in C#

Source Code:

using System;

class Program
{
  static void Main(string[] args)
  {
    two B = new two();
    B.show();
  }
}

class one
{
  private int x;
  protected int y;
  internal int z;
  public int a;
  protected internal int b;
}

class two: one
{
  public void show()
  {
    Console.WriteLine("Values are : ");
    y = 20;
    z = 30;
    a = 40;
    b = 50;

    Console.WriteLine(y);
    Console.WriteLine(z);
    Console.WriteLine(a);
    Console.WriteLine(b);

  }
}

Output: