using System;
namespace myApplication
{
class Base
{
public Base(){Func();}
public virtual void Func(){Console.Write("Base.Func ");}
}
class Sub:Base
{
public Sub(){Func();}
public override void Func(){Console.Write("Sub.Func ");}
}
class mainss
{
static void Main(string[] args)
{
Base obj = new Sub(); //执行完这句,就输出了两个Sub.Func
obj.Func();
}
}
}
结果:sub.Func Sub.Func Sub.Func
怎么会有三次输出?因为实例化的时候要执行子类和父类两个构造函数。