第八章-类和继承-屏蔽基类

55 阅读1分钟
namespace 屏蔽基类成员
{
    internal class Program
    {
        class someClass
        {
            public string A = "属于some";
            public void method()
            {
                Console.WriteLine("属于some的方法");
            }
        }
        class otherClass : someClass
        {
            new public string A = "属于other";//屏蔽基类字段
            new public void method()
            {
                Console.WriteLine("属于other的方法");
            }//屏蔽基类方法
        }
        static void Main(string[] args)
        {
            Console.WriteLine(new otherClass().A);
            new otherClass().method();
            Console.ReadLine();
        }
    }
}