Can the class containing `main` be private?

Calin Baenen - Nov 23 '20 - - Dev Community

I realize, that, in some cases, main shall not be private (and sometimes not protected), and in other cases, it may compile.

But, I was wondering if the class containing main can look like this:

private final class Main {
    public static void main(String[] args) { /* ... */ }
}
Enter fullscreen mode Exit fullscreen mode

.

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .