new override

    技术2022-05-11  85

    using System;using System.Collections.Generic;using System.Text;namespace wangyang {    /*C#中的new override*/    public class texttwo     {       public void Method_one()       {           Console.WriteLine("texttwo的方法一");       }       public virtual void Method_two()       {           Console.WriteLine("texttwo的方法二");       }    }    public class textthree : texttwo     {        public new void Method_one()         {            Console.WriteLine("隐藏基类的方法一");        }        public override void Method_two()        {            Console.WriteLine("重写基类TEXTTWO的方法二");        }    }    public class mainclass     {        public static void Main()        {            textthree text_obj = new textthree();            text_obj.Method_one();            text_obj.Method_two();            //多态            texttwo text_objtwo = text_obj;            text_objtwo.Method_one();            text_objtwo.Method_two();

            }    }} 


    最新回复(0)