nerdexam
Oracle

1Z0-803 · Question #86

Given: public class MainMethod { void main() { System.out.println("one"); } static void main(String args) { System.out.println("two"); } public static void main(String[] args) { System.out.println("th

The correct answer is C. three. The Java Virtual Machine (JVM) strictly requires a specific method signature as the program's entry point to begin execution. Only one of the provided methods matches this required signature.

Java Basics

Question

Given:

public class MainMethod { void main() { System.out.println("one"); } static void main(String args) { System.out.println("two"); } public static void main(String[] args) { System.out.println("three"); } void mina(Object[] args) { System.out.println("four"); } } What is printed out when the program is excuted?

Options

  • Aone
  • Btwo
  • Cthree
  • Dfour

How the community answered

(30 responses)
  • A
    3% (1)
  • B
    7% (2)
  • C
    87% (26)
  • D
    3% (1)

Why each option

The Java Virtual Machine (JVM) strictly requires a specific method signature as the program's entry point to begin execution. Only one of the provided methods matches this required signature.

Aone

The method `void main()` is not the correct entry point signature because it lacks the `public`, `static`, and `String[] args` parameters.

Btwo

The method `static void main(String args)` is not the correct entry point signature because it uses a single `String` parameter instead of a `String[]` array.

CthreeCorrect

The Java Virtual Machine (JVM) specifically looks for a method with the signature `public static void main(String[] args)` to start program execution. Any other method, even if named 'main', is considered an overloaded method or a regular method and will not be automatically invoked as the program's entry point.

Dfour

The method `void mina(Object[] args)` is not named 'main' and lacks the `public` and `static` modifiers, therefore it cannot be the program's entry point.

Concept tested: Java program entry point signature

Source: https://docs.oracle.com/javase/tutorial/getStarted/application/index.html

Topics

#main method#application entry point#method signature

Community Discussion

No community discussion yet for this question.

Full 1Z0-803 Practice