Overriding

Overriding

Overriding 是指子類有一個函式與父類中的某個虛函式的名字和簽名都相同。

Overriding :重寫
當一個子類的對象調用該虛函式時,就會執行子類中Overriding 的那個函式。所以Overriding 改變的是類的行為而不是類的接口。
Overriding:
Signature has to be the same. (including the return type)Overriding methods cannot be more private than the overridden methods.Overriding methods may not throw more checked exceptions than the overridden methods. But can throw no exception.Related directly to sub-classing. Overrides the parent class method. Resolved at run-time based on type of the object.Overriding method can call overridden method by super.methodName(), this can be used only to access the immediate super-class’s method.super.super won’t work. Also, a class outside the inheritance hierarchy can’t use this technique.

相關詞條

熱門詞條

聯絡我們