首页 > 其他 > 详细

override virtual

时间:2017-05-05 18:01:42      阅读:274      评论:0      收藏:0      [点我收藏+]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConstructCallVirtual
{
    class Program
    {
        static void Main(string[] args)
        {
            B b=new B();
        }
    }

    class A
    {
        public A()
        {
            Console.WriteLine("A()");
            DoSth();
        }
        public virtual void DoSth()
        {
            Console.WriteLine("A::DoSth()");
        }
    }

    class B:A
    {
        public B()
        {
            Console.WriteLine("B()");
            DoSth();
        }
        public virtual void DoSth()
        {
            Console.WriteLine("B::DoSth()");
        }
    }
//A()
//A::DoSth()
//B()
//B::DoSth()
//
}

 

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

namespace ConstructCallVirtual
{
    class Program
    {
        static void Main(string[] args)
        {
            B b=new B();
        }
    }

    class A
    {
        public A()
        {
            Console.WriteLine("A()");
            DoSth();
        }
        public virtual void DoSth()
        {
            Console.WriteLine("A::DoSth()");
        }
    }

    class B:A
    {
        public B()
        {
            Console.WriteLine("B()");
            DoSth();
        }
        public override void DoSth()
        {
            Console.WriteLine("B::DoSth()");
        }
    }
//A()
//B::DoSth()
//B()
//B::DoSth()
//
}

 

override virtual

原文:http://www.cnblogs.com/sky20080101/p/6814063.html

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