J.IX · Java 25 practice question
A developer runs the java launcher on a compiled class that declares only void main(int count) and inherits no other main methods. What happens?
Check answer and explanation
Correct answer: The launcher reports an error and terminates
Explanation
Because the class neither declares nor inherits a main method with a String[] parameter or with no parameters, the launcher reports an error and terminates.
Common trap
The launcher never supplies default primitive arguments to overloaded main methods. Launching a class without a valid main method is an error rather than a silent no-op.
Source: JEP 512: Compact Source Files and Instance Main Methods — Description
Checked against the cited text on 2026-11-25.