If we declare the class with default scope(non-public) and public main method it executes successfully. Here class scope is mote stricter than main method scope.
But if we declare main method as default, then JVM will throw error. Why?
class DefaultTest {
public static void main(String[] args) {
System.out.println("output.........");
}
}
Runs successfully but
class DefaultTest {
static void main(String[] args) {
System.out.println("output.........");
}
}
this won't.
I mean if the class itself is not public JVM can still access main method that means there is no need of main to be public. But if we don't declare it as public, it will throw an error.