DEV Community

Discussion on: Can `main` be `protected` (and be the program entry point) in Java?

Collapse
 
pgradot profile image
Pierre Gradot

No. Period.

Code:

public class HelloWorld{

     protected static void main(String []args){
        System.out.println("Hello World");
     }
}
Enter fullscreen mode Exit fullscreen mode

Output:

$javac HelloWorld.java
$java -Xmx128M -Xms16M HelloWorld
Error: Main method not found in class HelloWorld, please define the main method as:
   public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
Enter fullscreen mode Exit fullscreen mode