Override、Overwrite、Overload

  • In C++
    override: subclass method overrides base class method means:

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 Java
    override: subclass method overrides base class method means:

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翻译为重写,有的翻译为覆盖,搞得很混乱,所以尽量还是用英文来沟通吧。

你可能感兴趣的:(Override、Overwrite、Overload)