Protected Access modifier C#

Total Post:341

C#  .NET 
 892  View(s)
Rate this:
 I want to know what is Protected Access modifier and how to use please help me.
  1. Post:286

    Re: Protected Access modifier C#

    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!!


      Modified On Apr-10-2018 06:09:40 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.