gpt4 book ai didi

java - 为什么接口(interface)方法的作用域只是public?

转载 作者:行者123 更新时间:2023-12-01 23:53:03 25 4
gpt4 key购买 nike

interfaces为什么方法访问说明符只有 public为什么不protected

interface IPractice {
void test(); // it will be public
protected void test2(); // why this is not allowed
}

谁能给我解释一下吗?

最佳答案

接口(interface)的重点在于它向外界公开方法,因此可以隐藏实现细节。

界面内部发生的事情不应该被外界知道。

关于java - 为什么接口(interface)方法的作用域只是public?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16075223/

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