1Z0-808 · Question #15
Given: MainTest.java: public class MainTest { public static void main(int[] args) { System.out.println("int main " + args[0]); } public static void main(Object[] args) { System.out.println("Object…
The correct answer is C. String main 1. Option C is correct because the JVM always uses public static void main(String[] args) as the program entry point - this is a fixed contract, not subject to overload resolution. Command-line arguments (1 2 3) are always passed as String[], making args[0] the String "1", so the…
Question
Options
- Aint main 1
- BObject main 1
- CString main 1
- DCompilation fails
- EAn exception is thrown at runtime
How the community answered
(47 responses)- A2% (1)
- B11% (5)
- C81% (38)
- D2% (1)
- E4% (2)
Explanation
Option C is correct because the JVM always uses public static void main(String[] args) as the program entry point - this is a fixed contract, not subject to overload resolution. Command-line arguments (1 2 3) are always passed as String[], making args[0] the String "1", so the output is String main 1.
Why the distractors are wrong:
- A -
main(int[])is never called by the JVM as an entry point, and command-line args cannot be passed as primitives anyway. - B -
main(Object[])is also ignored by the JVM at startup;String[]is more specific and is the designated signature. - D - All three methods are syntactically valid Java; the code compiles without error.
- E - No exception occurs;
args[0]is"1"(a valid non-null String), so noArrayIndexOutOfBoundsExceptionis thrown.
Memory tip: Think of main(String[] args) as a hardcoded contract with the JVM - it won't "pick the best overload," it only looks for that exact signature. Any other main variant is just a regular method nobody automatically calls.
Topics
Community Discussion
No community discussion yet for this question.