gpt4 book ai didi

java - 当我可以实现完整的类时,为什么还需要接口(interface)?

转载 作者:行者123 更新时间:2023-11-30 09:18:13 25 4
gpt4 key购买 nike

<分区>

我试图理解 interface 的使用并阅读了 this article其中说:

Interfaces define a standardized set of commands that a class will obey.

The commands are a set of methods that a class implements.

The interface definition states the names of the methods and their return types and argument signatures. There is no executable body for any method that is left to each class that implements the interface.

我想问为什么我需要在 interface 中声明方法名称及其返回类型和参数签名,而我可以直接在 class 中实现它们?

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