隨筆 - 78  文章 - 25  trackbacks - 0
          <2009年10月>
          27282930123
          45678910
          11121314151617
          18192021222324
          25262728293031
          1234567

          常用鏈接

          留言簿

          隨筆分類(75)

          隨筆檔案(78)

          相冊

          實用Links

          我的Links

          搜索

          •  

          積分與排名

          • 積分 - 114401
          • 排名 - 515

          最新評論

          閱讀排行榜

          評論排行榜

          ■構造順序:子類對象在創建時,構造函數的調用順序是:首先調用父類構造函數,再調用自己的構造函數。默認情況下,子類構造函數中調用的是父類不帶參數的構造函數。
          ■base關鍵字與this關鍵字相似,它表示當前類的直接父類對象,需要明確使用父類成員時就要使用base關鍵字。

          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Text;

          namespace Inherit
          {
              
          /// <summary>
              /// parent class
              /// </summary>
              class BaseClass {
                  
          public BaseClass(int pubVal) {
                      System.Console.WriteLine(
          "BaseClass(int) created");
                  }
                  
          public BaseClass() {
                      System.Console.WriteLine(
          "BaseClass() created");
                  }
              }
              
          /// <summary>
              /// child class inherited from BaseClass
              /// </summary>
              class DevClass : BaseClass {
                  
          public DevClass() {
                      System.Console.WriteLine(
          "DevClass() created");
                  }
                  
          public DevClass(int pubVal):base(pubVal)
                  {
                      System.Console.WriteLine(
          "DevClass(int) created");
                  }
              }
              
          /// <summary>
              ///class for testing  result 
              /// </summary>
              class Program
              {
                  
          static void Main(string[] args)
                  {
                      DevClass devClass1 
          = new DevClass();
                      DevClass devClass2 
          = new DevClass(12);
                      System.Console.ReadLine();
                  }
              }
          }

          運行結果:
          BaseClass() created
          DevClass() created
          BaseClass(int) created
          DevClass(int) created



          posted on 2009-10-25 23:33 期待明天 閱讀(380) 評論(0)  編輯  收藏 所屬分類: CSharp
          主站蜘蛛池模板: 榆中县| 德化县| 安泽县| 桑植县| 西华县| 东乌珠穆沁旗| 贡觉县| 剑川县| 正镶白旗| 靖安县| 松潘县| 上林县| 共和县| 玉门市| 辉南县| 土默特左旗| 高安市| 广丰县| 类乌齐县| 麟游县| 开封县| 龙里县| 汝阳县| 射阳县| 共和县| 六枝特区| 开封县| 扶余县| 林芝县| 射阳县| 仪陇县| 梅河口市| 江孜县| 阳朔县| 台南县| 洛隆县| 玛纳斯县| 兴和县| 方城县| 临桂县| 宝鸡市|