1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 namespace ConsoleApp2
6 {
7 class Program
8 {
9 static void Main(string[] args)
10 {
11 //new D().DoWork(1);
12 //new F().DoSing();
13 //H.WriteH();
14 E.WriteE();
15 }
16 }
17
18 public class D
19 {
20 public D()
21 {
22 Console.WriteLine("Constructor of D is running");
23 }
24 public virtual void DoWork(int i)
25 {
26 // Original implementation.
27 Console.WriteLine("D");
28 }
29
30 public void DoEat()
31 {
32 Console.WriteLine("D is Eatting");
33 }
34
35 public static void DoComputer()//子类看不到
36 {
37 Console.WriteLine("D's static DoComputer");
38 }
39 }
40
41 public abstract class E : D
42 {
43 public abstract override void DoWork(int i);//对继承者来说还是虚的,必须被override
44 public virtual void DoJump()
45 {
46 Console.WriteLine("Jump");
47 }
48
49 public void DoSing()
50 {
51 Console.WriteLine("E is Sing");
52 }
53
54 public E()//实例化子类时被调用
55 {
56 Console.WriteLine("Constructor of E is running");
57 }
58
59 public static void WriteE()
60 {
61 Console.WriteLine("WriteE");
62 }
63 }
64 public class F : E
65 {
66 public F()
67 {
68 Console.WriteLine("Constructor of F is running");
69 }
70 public override void DoWork(int i)
71 {
72 // New implementation.
73 }
74
75 new public void DoSing()
76 {
77 Console.WriteLine("F is sing");
78 }
79
80
81 }
82
83 public static class H
84 {
85 //当调用静态方法时调用静态构造函数
86 static H()
87 {
88 Console.WriteLine("H was bore");
89 }
90
91 public static void WriteH()
92 {
93 Console.WriteLine("WriteH");
94 }
95 }
96
97
98 }
99
2 using System.Collections.Generic;
3 using System.Text;
4
5 namespace ConsoleApp2
6 {
7 class Program
8 {
9 static void Main(string[] args)
10 {
11 //new D().DoWork(1);
12 //new F().DoSing();
13 //H.WriteH();
14 E.WriteE();
15 }
16 }
17
18 public class D
19 {
20 public D()
21 {
22 Console.WriteLine("Constructor of D is running");
23 }
24 public virtual void DoWork(int i)
25 {
26 // Original implementation.
27 Console.WriteLine("D");
28 }
29
30 public void DoEat()
31 {
32 Console.WriteLine("D is Eatting");
33 }
34
35 public static void DoComputer()//子类看不到
36 {
37 Console.WriteLine("D's static DoComputer");
38 }
39 }
40
41 public abstract class E : D
42 {
43 public abstract override void DoWork(int i);//对继承者来说还是虚的,必须被override
44 public virtual void DoJump()
45 {
46 Console.WriteLine("Jump");
47 }
48
49 public void DoSing()
50 {
51 Console.WriteLine("E is Sing");
52 }
53
54 public E()//实例化子类时被调用
55 {
56 Console.WriteLine("Constructor of E is running");
57 }
58
59 public static void WriteE()
60 {
61 Console.WriteLine("WriteE");
62 }
63 }
64 public class F : E
65 {
66 public F()
67 {
68 Console.WriteLine("Constructor of F is running");
69 }
70 public override void DoWork(int i)
71 {
72 // New implementation.
73 }
74
75 new public void DoSing()
76 {
77 Console.WriteLine("F is sing");
78 }
79
80
81 }
82
83 public static class H
84 {
85 //当调用静态方法时调用静态构造函数
86 static H()
87 {
88 Console.WriteLine("H was bore");
89 }
90
91 public static void WriteH()
92 {
93 Console.WriteLine("WriteH");
94 }
95 }
96
97
98 }
99