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:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | 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: