为什么我们不能在不修改"public"的情况下实现从接口到抽象class的方法?

why we can't implement methods from interface to abstract class, without modifying "public"?

接口:

interface MasterPlan{
    void getRate();
}

摘要class:

abstract class Plan implements MasterPlan{
    abstract void getRate();
} }

在这种情况下,如果不在 getRate() 方法中使用 public 修饰符,我无法实现 MasterPlan 接口。

public abstract void getRate();

这是正常行为。

我知道接口中的默认修饰符是 default。在实现的摘要 class 中没有 public 修饰符时出现此错误的原因是什么?

您面临的问题是 Interface 中的每个方法都是 public。因此,如果你有一个 abstract class 实现了 Interface,那么其中的方法就是 public。您无法更改已定义方法的可见性。

All abstract, default, and static methods in an interface are implicitly public.

接口有具有隐式属性的方法,一旦声明了方法,当你定义它或实现它时,你就不能改变它的访问修饰符。

否则您可以将您的 class 声明为私有、受保护等

oracle document defining interfaces

可以请教更多热心的帮助。