//继承类始终默认调用父类的无参构造器,如果父类定义了带参构造器,那么必须显示声明无参构造函数,否则继承的子类就必须指定调用父类的哪个带参构造器
using System;
namespace Constructor7
{
    class A
    {
        public A()
        {
            Console.WriteLine("我是A的无参构造函数");
        }
        public A(string s)
        {
            Console.WriteLine("我是A带了S的构造函数");
        }
    }
    class B:A
    {
        public B()
        {
            Console.WriteLine("我是B的无参构造函数");
        }
        public B(string s)
        {
            Console.WriteLine("我是B带了S的构造函数");
        }
    }
    class Test
    {
        static void Main()
        {
            B b = new B();//自动调用了A的无参构造函数
            B b1 = new B("dfsafdas");//还是一样自动调用A的无参构造函数
        }
    }
}
posted on 2008-01-21 21:28  glave  阅读(315)  评论(0)    收藏  举报