【发布时间】:2017-05-10 12:00:58
【问题描述】:
我有一个基类和派生类,基类有两个在派生类中被覆盖的方法。让我们看下面的场景:
我的基类
public class BaseClass
public Overridable function method1()
method2()
End Function
public Overridable function method2()
' Empty !!!
End Function
End class
我的派生类
public class DerivedClass
public Overrides function method1()
MyBase.method1()
End Function
public Overrides function method2()
' Some code !!
End Function
End class
现在我已经创建了派生类的一个实例并调用了method1()。
Dim obj as new DerivedClass()
obj.method1()
method1() 派生调用base 中的method1(),后者调用base 中的method2。对我来说奇怪的是base中的method2,它是空的,在派生中调用了method2! ..
谁能向我解释发生了什么以及如何使用继承调用方法?这个层次结构应用了什么概念?
【问题讨论】: