複製鏈接
請複製以下鏈接發送給好友

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.