Difficulty: Easy
Correct Answer: 1, 2 and 3 only
Explanation:
Introduction:
This question tests understanding of Java array typing rules: homogeneity, object arrays, and multidimensional arrays. Knowing what is and is not type-safe in Java is essential for avoiding ClassCastException and compile-time errors.
Given Data / Assumptions:
Concept / Approach:
Java arrays are homogeneous: every element has the same declared type. int[] holds primitives of type int only; String[] holds references to String objects only. Multidimensional arrays (like int[][] or String[][]) are fully supported. A single array mixing primitives and reference types (e.g., ints and Strings) is not allowed. An Object[] could hold both, but then integers would be boxed as Integer and the statement specifically says an array of integers and Strings together, which is not a single strongly typed array of those two distinct types.
Step-by-Step Solution:
Verification / Alternative check:
You can compile small snippets: int[] a = {1, 2}; String[] s = {"a", "b"}; int[][] m = {{1,2},{3,4}}; // all OKObject[] mix = {1, "x"}; // compiles, but this is not an 'array of integers and strings'; it is an Object[] with boxing
Why Other Options Are Wrong:
'All' – wrong because (4) is invalid. '1 and 2 only' – ignores valid multidimensional arrays. '1, 3 and 4 only' – includes invalid (4) and excludes (2).
Common Pitfalls:
Confusing Object[] (heterogeneous) with a typed array; forgetting autoboxing implications; mixing primitives and references in a single typed array.
Final Answer:
1, 2 and 3 only
Discussion & Comments