Difficulty: Easy
Correct Answer: null
Explanation:
Introduction / Context:
This question tests understanding of default array initialization and bounds when partially populating an array from the command line. The code assigns only as many elements as args provides, then prints the element at index 2.
Given Data / Assumptions:
Concept / Approach:
Printing names[2] after copying only two arguments should yield null since names[2] was not assigned any value and remains at its default reference value.
Step-by-Step Solution:
Verification / Alternative check:
If the invocation were > java X a b c, names[2] would print c. With no args, names[0] would also be null.
Why Other Options Are Wrong:
Common Pitfalls:
Confusing default null with an empty string, or thinking println throws when printing null.
Final Answer:
null
Discussion & Comments