Why does the following code work with an interface, but without any class?

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

There is no defined class in the above code, but the program still executes. But, as far as I know, there can be no static method inside the interface. And each program must contain at least one core function.

+5
source share
1 answer

Because you are using Java version 8.

Starting with Java 8, you can have static methods inside the interface.

And main () also runs from interfaces (even from enumerations) if you keep the correct signature.

+4
source

Source: https://habr.com/ru/post/1693841/


All Articles