首页 > Windows开发 > 详细

C#中的继承与覆盖

时间:2017-07-12 09:27:10      阅读:250      评论:0      收藏:0      [点我收藏+]

原文发布时间为:2009-03-03 —— 来源于本人的百度文章 [由搬家工具导入]

//using System;
//using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
   public class Program
    {
       public static void Main()
        {
            Parent p = new Son();//输出 A from Parent! B from Son! 若改成Parent p = new Parent();那输出的都是A from Parent! B from Parent!
            p.A();
            p.B();
            Console.ReadLine();
        }
    }

    class Parent
    {
       public void A()
        {
            Console.WriteLine("A from Parent!");
        }
      public virtual void B()
        {
            Console.WriteLine("B from Parent!");
        }
    }

    class Son : Parent
    {
      public new void A()
        {
            Console.WriteLine("A from Son!");
        }
      public override void B()
        {
            Console.WriteLine("B from Son!");
        }
    }
}

C#中的继承与覆盖

原文:http://www.cnblogs.com/handboy/p/7153253.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!