天天看點

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.");

        }

    }

}

繼續閱讀