常建57

路漫漫其修远兮。。。

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

Case:class A has a construct. class B is inherit from class A and B also has a construct. What's the order of the construct execute?

Result: construct A -> construct B.

Sample:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 
 6 namespace TestInheritConstruct
 7 {
 8     public class Program
 9     {
10         public static void Main(string[] args)
11         {
12             B b = new B();
13             Console.ReadLine();
14         }
15     }
16 
17     public class A
18     {
19         public A()
20         {
21             Console.WriteLine("Construct A.");
22         }
23     }
24 
25     public class B : A
26     {
27         public B()
28         {
29             Console.WriteLine("Construct B.");
30         }
31     }
32 }
View Code

 

 

posted on 2013-12-25 22:39  常建57  阅读(333)  评论(0编辑  收藏  举报