c#中 构造函数 继承

 

class baseClass
{
    public string Name;

    public baseClass()
    {

    }
    public baseClass(string name)
    {
     Name = name;
    }
}

class testClass : baseClass
{
    public    string    Sex;

    public testClass()//隐式的调用了父类的构造函数,等价于public testClass() :base()
    {

    }

    public testClass(string name,string sex) : base(name)
    {
     this.Sex = sex;
    }
}

private void Page_Load(object sender, System.EventArgs e)
   {
    // 在此处放置用户代码以初始化页面
    testClass tc = new testClass("小张","男");

    Response.Write(tc.Name + "," + tc.Sex);
   
   }

posted @ 2008-10-21 15:45  游侠_1  阅读(229)  评论(0)    收藏  举报