nerdexam
Oracle

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…

Java Basics

Question

Given: public class App { public static void main (String[] args) { System.out.println ("Hello Java!"); } } Which statement is true about the main method?

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)
  • A
    90% (35)
  • B
    5% (2)
  • C
    3% (1)
  • D
    3% (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 for main(String[]), and Integer[] would not be recognized as an entry point.
  • C is false - the enclosing class does not need to be public; only the main method itself needs to be public.
  • D is false - main is an ordinary method and can be called by name (e.g., App.main(args) or main(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

#main method#static methods#method declarations#JVM entry point

Community Discussion

No community discussion yet for this question.

Full 1Z0-811 Practice