码迷,mamicode.com
首页 > 其他好文 > 详细

override virtual

时间:2017-05-05 18:32:10      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:bsp   struct   space   dos   text   lin   rtu   system   class   

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

标签:bsp   struct   space   dos   text   lin   rtu   system   class   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!