Home > DeveloperSection > Forums > Protected Access modifier C#
Ankit Singh

Total Post:341

Posted on    November-25-2015 10:04 PM

 C# C#  .NET 

 1 Reply(s)
 463  View(s)
Rate this:
 I want to know what is Protected Access modifier and how to use please help me.

aditya kumar Patel

Total Post:254

Posted on    November-25-2015 10:10 PM

The protected access modifier hides its member variables and functions from other classes and objects. This type of variable or function can only be accessed in child class. It becomes very important while implementing inheritance.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Protected_Modifier
    class ProtectedClass
        // String Variable declared as protected
        protected string ComputerName;
        public void print()
            Console.WriteLine("\nMy name is " + ComputerName);

    class MainClass : ProtectedClass // Inherit access class
        static void Main(string[] args)
            MainClass p = new MainClass();
            Console.Write("Enter your CounputerName:\t");
            p.ComputerName = Console.ReadLine(); // No Error!!


Don't want to miss updates? Please click the below button!

Follow MindStick