gpt4 book ai didi

java - 延伸 2 节课 - 填空 - 最后一次考试排练

转载 作者:行者123 更新时间:2023-11-29 04:44:24 28 4
gpt4 key购买 nike

我正在准备 Java 期末考试。我遇到一道题,需要填空。

需要填空的相关代码

____ ____ C {}
____ B extends ____ , C {}

问题是:我可以插入所有这些空白来编译我的程序吗?

我知道我不能创建从 2 个类扩展而来的类。但也许有某种关键字可以编译。

我个人认为C之前应该有“implements”关键字,然后它看起来像这样。可能是上一学年的人打错了字。

public interface C {}
class B extends Object implements C {} //good enough

我也可以用大片段填充最后一个空白,我在其中声明新类,但我认为情况并非如此。

还是。我可以只填写空白来编译第一个片段中的代码吗?

最佳答案

C 和 B 都应该是接口(interface)。下面的示例(我在其中一个空白中使用了 Closeable 接口(interface),但您可以使用 JDK 中已知的任何接口(interface))

public interface C {}
interface B extends Closeable, C {}

当接口(interface)相互继承时,它们使用extends 关键字而不是implements(当类从接口(interface)继承时使用)。

关于java - 延伸 2 节课 - 填空 - 最后一次考试排练,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37820010/

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