为什么以下代码使用接口但没有定义任何 class?

Why is the following code working with an interface but without any class defined?

interface Main 
{
public static void main(String[] args) 
{
    System.out.println("Inside main");
    int a = 4 , b = 6 ;
    System.out.println(a+b);
}
}

在上面的代码中,没有定义class,但程序仍在执行。但据我所知,接口中不能有任何静态方法。并且,每个程序都应该至少包含一个主要功能。

因为,您使用的是 Java 版本 8。

从 Java8 开始,您可以在接口中使用静态方法。

并且 main() 也从接口(甚至从枚举)获取 运行,只要您保持正确的签名。