class Program { static void Main(string[] args) { B b = new B(); } } class A { public A() { Console.WriteLine("A类的构造器"); } } class B :A { public B() { Console.WriteLine("B类的构造器"); }
class Program { static void Main(string[] args) { B b = new B("ok"); } } class A { public A() { Console.WriteLine("A类的构造器"); } } class B :A { public B() { Console.WriteLine("B类的构造器"); } public B(string name) { Console.WriteLine("B类中带参数的构造器,传入的值为:" + name); } }
class A { public A() { Console.WriteLine("A类的构造器"); } public A(string name) { Console.WriteLine("A类的构造器,传入的值为:" + name); } } class B :A { public B() { Console.WriteLine("B类的构造器"); } public B(string name):base(name) //调用父类中带参数的构造器 { Console.WriteLine("B类中带参数的构造器,传入的值为:" + name); } }