using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//构造器初始化
//1.派生类构造器调用基类构造器(除System.Object构造器外,所有C#对象都在执行构造器的第一行代码之前调用基类构造器)
//2.初始化器的两种形式:
// (1)base() 调用当前类的基类构造器
// (2)this() 可以让当前类调用自身中定义的另一个构造器
namespace InitialConstruct
{
class BaseClass
{
public BaseClass()
{
Console.WriteLine("[BaseClass.BaseClass] "+"Construct called");
}
}
class DerivedClass : BaseClass
{
//下面的2个个构造器等效
public DerivedClass()
{
Console.WriteLine("[DerivedClass.Derived] "+"Construct called");
}
//public DerivedClass()
// : base()
//{
// Console.WriteLine("[DerivedClass.Derived] " + "Construct called");
//}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("[Main] Instantianting a "+ "DerivedClass object");
DerivedClass derived = new DerivedClass();
Console.ReadKey();
}
}
}