interface Main
{
public static void main(String[] args)
{
System.out.println("Inside main");
int a = 4 , b = 6 ;
System.out.println(a+b);
}
}
In the above code, there is no class defined but the program is still getting executed. But as far as I know, there cannot be any static method inside an Interface. And, every program should contain at least one main function.
Because, you are using Java version 8.
From Java 8 on, you are allowed to have static methods inside an interface.
And main() gets run from interfaces as well (even from enums), as long as you keep the correct signature.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With