Learnitweb

main method inside interface

Yes, you can defined main method inside interface in Java 8.

Prior to Java 8, static methods were not allowed in interface. In Java 8, you can define static method inside interface.

main method is just another static method, so you can define main method inside interface.

Since an interface is saved as .java file and generates a .class file on compilation, you can run main method of an interface like any other class. So following is perfectly valid:

public interface Foo {
	public static void main(String args[]) {
		System.out.println("inside main method of interface Foo");
	}
}

You can also run the above main method.

>java Foo
inside main method of interface Foo