[你必须知道的.NET]第十五回:继承本质论
2009-11-03 23:18
246 查看
http://developer.51cto.com/art/200910/155202.htm
本文将介绍以下内容:
什么是继承?
继承的实现本质
1. 引言
关于继承,你是否驾熟就轻,关于继承,你是否了如指掌。
本文不讨论继承的基本概念,我们回归本质,从编译器运行的角度来揭示.NET继承中的运行本源,来发现子类对象是如何实现了对父类成员与方法的继承,以最为简陋的示例来揭示继承的实质,阐述继承机制是如何被执行的,这对于更好的理解继承,是必要且必然的。
2. 分析
下面首先以一个简单的动物继承体系为例,来进行说明:
12
本文将介绍以下内容:
什么是继承?
继承的实现本质
1. 引言
关于继承,你是否驾熟就轻,关于继承,你是否了如指掌。
本文不讨论继承的基本概念,我们回归本质,从编译器运行的角度来揭示.NET继承中的运行本源,来发现子类对象是如何实现了对父类成员与方法的继承,以最为简陋的示例来揭示继承的实质,阐述继承机制是如何被执行的,这对于更好的理解继承,是必要且必然的。
2. 分析
下面首先以一个简单的动物继承体系为例,来进行说明:
public abstract class Animal { public abstract void ShowType(); public void Eat() { Console.WriteLine("Animal always eat."); } } public class Bird: Animal { private string type = "Bird"; public override void ShowType() { Console.WriteLine("Type is {0}", type); } private string color; public string Color { get { return color; } set { color = value; } } } public class Chicken : Bird { private string type = "Chicken"; public override void ShowType() { Console.WriteLine("Type is {0}", type); } public void ShowColor() { Console.WriteLine("Color is {0}", Color); } }
12
相关文章推荐
- [你必须知道的.NET]第十五回:继承本质论 观后感
- 【转】[你必须知道的.NET]第十五回:继承本质论
- [你必须知道的.NET]第十五回:继承本质论
- [你必须知道的.NET]第十五回:继承本质论
- [你必须知道的.NET] 第十五回:继承本质论(转CNBlog)
- [你必须知道的.NET] 第十五回:继承本质论
- [你必须知道的.NET]: 继承本质论
- [你必须知道的.NET]第二十七回:interface到底继承于object吗?
- 读《必须知道的.NET》笔记(一) 继承
- [你必须知道的.NET]第二十七回:interface到底继承于object吗?
- [你必须知道的.Net]读书笔记--override与new在继承中的区别
- 你必须知道的.net学习总结之继承
- [你必须知道的.NET]第三十五回,判断dll是debug还是release,这是个问题
- [你必须知道的.NET]第二十回:学习方法论
- JavaScript面向对象(二)--前端必须知道的原型和继承
- 读你必须知道的.NET-override,new
- [你必须知道的.NET]第三十五回,判断dll是debug还是release,这是个问题
- [你必须知道的.NET]第十回:品味类型---值类型与引用类型(下)-应用征途
- [导入][你必须知道的.NET]第十回:品味类型---值类型与引用类型(下)-应用征途
- [你必须知道的.NET]第十三回:从Hello, world开始认识IL