gpt4 book ai didi

java - 在JAVA中将引用变量声明为接口(interface)类型有什么好处?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:03:30 25 4
gpt4 key购买 nike

<分区>

我正在阅读 this PowerPoint presentation当我遇到这个时:

When you call a method through one of these references, the correct version will be called based on the actual instance of the interface being referred to. This is one of the key features of interfaces. The method to be executed is looked up dynamically at run time, allowing classes to be created later than the code which calls methods on them.

谁能给我解释一下这个概念?我引用了一些网站和书籍,但我仍然不清楚这个概念是如何运作的。从上面的行可以知道它调用了正确版本的方法。它是如何工作的,什么时候应该将对象转换为接口(interface)类型。

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