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

An interesting piece of code

时间:2015-03-30 20:43:58      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

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

namespace ConsoleApplication1

{
class A
{
public virtual void Movie()
{
Console.WriteLine("A");
}
}
class B : A
{
public override void Movie()
{
Console.WriteLine("B");
}
}
class C : B
{
public new virtual void Movie()
{
Console.WriteLine("C");

}

}
class D : C
{
public override void Movie()
{
Console.WriteLine("D");
}

}
class Program
{
static void Main(string[] args)
{
A objA = new D();
A objB = new B();
C objC = new D();
A objD = new A();
objA.Movie();
objB.Movie();
objC.Movie();
objD.Movie();
Console.ReadLine();
}
}
}

 

技术分享

 

the reason is like:

B overrides A ,it‘s not virtual.

so the inherited one stops when it can‘t go further or it reach to itself. 

技术分享

An interesting piece of code

标签:

原文地址:http://www.cnblogs.com/itria/p/4378935.html

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