在java中实现接口方法是否覆盖 [英] Implementing a method of interface is overriding or not in java

查看:180
本文介绍了在java中实现接口方法是否覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这可能很疯狂,但今天我的一位朋友在询问我们何时在java中实现接口时感到困惑,它被视为方法覆盖。我告诉他,当我们实现任何接口时,我们第一次提供方法的工作(定义)时,它不会重写。为了支持多重继承,java提供了接口,但他并不相信并且在争论。请介绍一下这个话题。

I know this might be crazy but today one of my friend puzzled by asking when we implement an interface in java is it considered as method overriding. I told him it is not overriding as we are providing working(definition) of method first time when we implement any interface. To support multiple inheritance java provide interface but he was not convinced and was arguing. Please bring some light on to the topic.

推荐答案

当存在该方法的现有实现时,术语覆盖适用。正确的术语是实现接口和其他抽象声明。

The term "overriding" applies when there is an existing implementation of the method . The correct term is "implementing" for interfaces and other abstract declarations.

@Override 标签用于两者case - 在以下情况下使用:

The @Override tag is used for both cases - it is used when:


该方法会覆盖或实现在超类型中声明的方法。 - javadocs

The method does override or implement a method declared in a supertype. --javadocs

来自维基百科


在面向对象编程中,方法覆盖是一种语言特性,它允许子类或子类提供方法的特定实现已由其超类或父类之一提供

请注意,接口可以默认方法 - 重新定义这些方法覆盖

Note that interfaces can have default methods - redefining these methods overrides them:


当您扩展包含默认方法的接口时,您可以...重新定义默认方法,该方法会覆盖它。

When you extend an interface that contains a default method, you can ... redefine the default method, which overrides it.

除了链接到规范来源之外,我是不确定与朋友赢得语义争论的建议是什么。也许你可以问他实现和覆盖之间的区别,以及他将使用什么词而不是重写重新定义现有方法的概念。

Besides linking to "canonical" sources, I'm not sure what advice to offer on winning a semantic argument with your friend. Perhaps you could ask him what the distinction is between "implementing" and "overriding", and what word he would use instead of "overriding" for the concept of redefining an existing method.

这篇关于在java中实现接口方法是否覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆