new override

来源:互联网 发布:vb编程乐园 编辑:程序博客网 时间:2024/05/16 11:48

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();


        }
    }