天天看点

C#的 派生类 构造函数使用 例子。

//zhangzhicong 2007-03-10

using System;

using System.Collections.Generic;

using System.Text;

namespace t070309

{

    class Program

    {

        static void Main(string[] args)

        {

            b bb = new b();

            Console.ReadKey();

        }

    }

    public class a

    {

        //无参数,最好要定义一个无参数的构造函数,这是很好的习惯

        public a()

        {

            Console.WriteLine("a init null");

        }

        //一个参数

        public a(string m)

        {

            Console.WriteLine("a init m={0}.", m);

        }

        //两个参数

        public a(string m,string n )

        {

            Console.WriteLine("a init m={0},n={1}.", m,n);

        }

    }

    public class b : a

    {

        private static string m = "zhangzhicong";

        private static string n = "man";

        public b():base()

        {

         Console.WriteLine("b init null.");

        }

    }

}