Difficulty: Medium
Correct Answer: 2, 4 and 5
Explanation:
Introduction / Context:
This problem distinguishes reference comparison for arrays from numeric comparison for primitives (with widening conversions). It asks you to evaluate five boolean expressions concerning float arrays, a copied reference, and primitive values.
Given Data / Assumptions:
Concept / Approach:
For arrays, ==
compares object identity (same reference), not contents. For primitives, ==
compares numeric values after standard promotions (e.g., long with float). A comparison between a reference type and a primitive is a compile-time error.
Step-by-Step Solution:
Verification / Alternative check:
Printing System.out.println(f1 == f3)
yields true; modifying f1[0] is visible via f3 due to shared identity. Numeric comparisons align with Java promotion rules.
Why Other Options Are Wrong:
Common Pitfalls:
Assuming arrays are compared by contents with ==
(use Arrays.equals for that), and overlooking compile-time type errors in mixed comparisons.
Final Answer:
2, 4 and 5
Discussion & Comments