美文网首页
Override、Overwrite、Overload

Override、Overwrite、Overload

作者: YuWenHaiBo | 来源:发表于2018-02-11 10:22 被阅读19次
    • 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

          本文链接:https://www.haomeiwen.com/subject/fujktftx.html