访问修饰符 protected(s)

protected

受保护的:可以在当前类的内部以及该类的子类中可以访问。

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

namespace protected访问修饰符
{
    class Program
    {
        static void Main(string[] args)
        {
            //protected public private
            Person p = new Person();
            p.Name = "2";
        }
    }
    public class Person
    {
        protected  string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }
    }


    public class Student:Person
    {
        public void Test()
        {
            _name = "1";
        }
    }
}

 

posted @ 2021-07-06 21:08  静态类  阅读(61)  评论(0)    收藏  举报