Why does the following code compile and run successfully in Java 8+eclipse?
package package1;
interface A
{
static void main(String[] args) {
System.out.println("Hi");
}
}
If A is changed to a class, the run-time requires it to be a public class, but not so for an interface. This seems inconsistent.
EDIT: The above statment that I made when posting the question was WRONG. ( I must have been tired and misread the errors ). Java does NOT require the class hosting main to be public, only the method. However, it is a bit inconsistent that the type hosting main does not have to be public, while the main method does.
If A is changed to a class, the run-time requires it to be a public class.
No it doesn't. It requires the method to be public, and methods in interfaces already are public.
but not so for an interface.
Not so.
This seems inconsistent.
It isn't. You misread the error message.