Override、Overwrite、Overload

2018-02-11  本文已影响19人  YuWenHaiBo

in different range (in derived class and base class)
the same function name
the same function signature
the return type conforms covariance
the base class method is virtual
overload: function overloading means:

the same range (in the same class)
the same function name
different function signature
overwrite: subclass method hides base class method means:

in different range (in derived class and base class)
the same function name
two cases on parameters ( signature? ):
the same parameters, the base class method is not virtual
different parameters

in different range (in derived class and base class)
the same function name
the same function signature
the return type conforms covariance
In Java, when you override a method, you could add @Override annotation on that method, this will let the compiler to help you check out whether you actually override a method or just mistake or misspell something.

overload: function overloading means:

the same range (in the same class)
the same function name
different function signature

这里不对override和overwrite进行翻译,基本上网络上有的把override翻译为重写,有的翻译为覆盖,搞得很混乱,所以尽量还是用英文来沟通吧。

上一篇下一篇

猜你喜欢

热点阅读