首先實體劃一個 testInher ,在這時候,我們會看到因為建構式的關係,
出現這兩個訊息
00 message of ExampleClass: in class ExampleClass()
01 message of inher(): in class inher : ExampleClass
接著,當我們呼叫 testInher.echoMsgInher(); 時候,
由於此方法在父 class 宣告為 public virtual void echoMsgInher() ,有使用 virtual
故在繼承之後,需要 override 這個方法
此外,由於 base.echoMsgInher(); ,因此會執行父class 裡面的 方法內容
故 執行結果後,會出現
03 message in Father: echoMsgInher
04 message of son: in class inher : ExampleClass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
執行結果:
00 message of ExampleClass: in class ExampleClass()
01 message of inher(): in class inher : ExampleClass
03 message in Father: echoMsgInher
04 message of son: in class inher : ExampleClass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters