gpt4 book ai didi

java - 接口(interface)扩展等同于继承吗? ( java )

转载 作者:行者123 更新时间:2023-12-02 18:18:37 24 4
gpt4 key购买 nike

我有一个关于继承定义的理论问题。一个月前我做了一个测试,我们必须给出一个继承的例子。

这是我的回答:

public interface UserRepository extends CrudRepository<User, Long>

根据定义,extend 关键字指示正在定义的类是使用继承从基类派生的。然而,我的教授认为这个答案是错误的,并评论说我的示例是一个接口(interface)扩展,与继承无关。

接口(interface)扩展和继承之间有什么区别?为什么我的答案是错误的,我是否混淆了继承的定义?

最佳答案

嗯,Java Language Specification § 9.1.3提到这一点:

If an extends clause is provided, then the interface being declared extends each of the specified interface types and therefore inherits the member classes, member interfaces, instance methods, and static fields of each of those interface types.

(强调我的。)

所以是的,我很确定这是继承。

关于java - 接口(interface)扩展等同于继承吗? ( java ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71199139/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com