Difficulty: Easy
Correct Answer: An exception is thrown at runtime.
Explanation:
Introduction / Context:
This program highlights array bounds and evaluation order in Java. Even though the final print references s2, the statements assigning s1…s4 execute sequentially first. If any assignment throws an exception, the print is never reached.
Given Data / Assumptions:
Concept / Approach:
Accessing args[4] with only four elements triggers ArrayIndexOutOfBoundsException. This happens before the System.out.print call, so nothing is printed successfully.
Step-by-Step Solution:
Verification / Alternative check:
Removing the s4 line or guarding with if (args.length > 4) would allow the print “ args[2] = 3”.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting that args is zero-based; assuming later statements are skipped even when earlier ones fail.
Final Answer:
An exception is thrown at runtime.
Discussion & Comments