This is a coding detail I ran into this morning that surprised me. By mistake, I compiled and ran the following, in the file A.java:
class A {
public static void main(
String[] args) {
System.out.println("Hello");
}
}
Then, I noticed that class A was not declared "public".
I'm so used to reading stuff like: "A
java source file must contain one public class, which has the same name as the source file."
I see that I need to leave "main" as public; after all, main must be called from the "outside". But wouldn't we say the same thing about class A, that the class must be visible from the "outside"? (Outside the package.)