Difficulty: Easy
Correct Answer: It prints f2[0] = 0.0
Explanation:
Introduction / Context:
This question is about Java array references, aliasing, and default values of primitive arrays. Java initializes arrays of primitives to their default values: 0 for numeric types, false for boolean, and \u0000 for char. Assigning one array reference to another creates an alias, not a copy.
Given Data / Assumptions:
Concept / Approach:
Because f2 and f1 reference the same array, reading f2[0] is equivalent to reading f1[0], which is the default 0.0f for a newly allocated float array.
Step-by-Step Solution:
Verification / Alternative check:
Writing f1[0] = 2.5f before printing would make f2[0] also 2.5 because of aliasing.
Why Other Options Are Wrong:
Common Pitfalls:
Expecting C-like uninitialized memory or assuming f2 becomes a deep copy rather than an alias.
Final Answer:
It prints f2[0] = 0.0
Discussion & Comments