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.
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)- A3% (1)
- B7% (2)
- C87% (26)
- D3% (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.
The method `void main()` is not the correct entry point signature because it lacks the `public`, `static`, and `String[] args` parameters.
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.
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.
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
Community Discussion
No community discussion yet for this question.