1Z0-811 · Question #51
Given: public class App { public static void main (String[] args) { System.out.println ("Hello Java!"); } } Which statement is true about the main method?
The correct answer is A. It can be a non-static method. Option A is correct because while the conventional JVM entry point requires static, you can legally define a non-static (instance) method named main in Java - it's valid syntax. Modern Java (21+) even supports instance main methods as actual program entry points via JEP…
Question
Options
- AIt can be a non-static method.
- BIts parameter can be of type Integer [].
- CIt cannot be defined in a non-public class.
- DIt cannot be invoked by its name.
How the community answered
(39 responses)- A90% (35)
- B5% (2)
- C3% (1)
- D3% (1)
Explanation
Option A is correct because while the conventional JVM entry point requires static, you can legally define a non-static (instance) method named main in Java - it's valid syntax. Modern Java (21+) even supports instance main methods as actual program entry points via JEP 463/495.
Why the distractors are wrong:
- B is false - the parameter must be
String[]; the JVM specifically looks formain(String[]), andInteger[]would not be recognized as an entry point. - C is false - the enclosing class does not need to be
public; only themainmethod itself needs to bepublic. - D is false -
mainis an ordinary method and can be called by name (e.g.,App.main(args)ormain(args)from within the same class).
Memory tip: Focus on what the JVM requires (public, static, void, String[] parameter) versus what Java the language actually enforces. Many exam distractors confuse JVM convention with language rules - C and D both fall into that trap.
Topics
Community Discussion
No community discussion yet for this question.