派生类创建实例时,程序路径
时间:2014-03-05 17:53:21
收藏:0
阅读:449
路径:
派生类字段-->派生类构造函数之前-->被继承类字段-->被继承类构造函数-->被继承类构造函数
实例:
public class A { int m = 4; public A() { PrintFields(); } public virtual void PrintFields() { } } public class B : A { int x = 1; int y; public B() { y = -1; } public override void PrintFields() { Console.WriteLine("x={0},y={1}", x, y); } }
结果:
x=1,y=0
原文:http://www.cnblogs.com/fang-beny/p/3581447.html
评论(0)