J.IX · Java 25 practice question

A developer launches a Java 25 subclass that declares no main method of its own, but its superclass declares a package-accessible no-arg void main() method and no String[] main method. What does the launcher do?

Choose one answer
Check answer and explanation

Correct answer: It chooses and invokes the inherited no-arg main method

Explanation

Because the class neither declares nor inherits a main method with a String[] parameter, the launcher falls back to the inherited no-arg main method and invokes it.

Common trap

The launcher explicitly checks for both declared and inherited main methods. Both String[] and no-parameter main methods can be inherited and chosen by the launcher.

Source: JEP 512: Compact Source Files and Instance Main Methods — Description
Checked against the cited text on 2026-11-25.

Report an error in this question