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

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • another琼阅读 346评论 0 0
  • 自10年入长沙一师求学以来,离家就是常见的事。对于从小被放养的我而言,我喜欢并热爱出走,享受一个不一样的经历,在一...
    96大阳阅读 222评论 0 2
  • 2018年钟声即将响起,2017年渐行渐远。时间就是这么快,明明感觉2017年还未真正的开始,可实际上却迎来了年末...
    宁博Villa阅读 233评论 1 1
  • 香花引蜂 臭水留蝇 你厌 它喜 我何必
    孔十八阅读 170评论 0 0
  • 亦舒总是在写女子的故事,或热烈冷酷,或情谊缱绻。而我们总是陷在向往又恐惧的情绪里,看她笔下女子一生波折纷扰,看她笔...
    潼妈阅读 1,028评论 0 0

友情链接更多精彩内容