Exams Knowledge Hub

MCQs for Competitive Exams, School & College Exams

Module: | Classes, Objects, OOPs & Inheritance

Q35: Consider the following statements regarding multidimensional and jagged arrays in Java:

1. Multidimensional arrays in Java are technically implemented as arrays of arrays, naturally allowing developers to create highly irregular structures known as jagged arrays.
2. When declaring a two-dimensional jagged array using the 'new' keyword, it is architecturally mandatory to specify the exact size of the outermost (row) dimension during the initial instantiation.
3. Java structurally forces all inner sub-arrays within a jagged array to reside in perfectly contiguous memory blocks to heavily optimize CPU cache locality for intensive scientific computing.

Which of the above statements is/are correct?
A
Only 1 and 2
B
Only 1 and 3
C
Only 2 and 3
D
1, 2, and 3 [] matrix = new int[3][]'. The outer array (size 3) is created holding three null references. The developer must manually instantiate and attach the inner arrays of varying sizes (e.g., 'matrix[0] = new int[5]; matrix[1] = new int[2];'). Historical/Related Context: Unlike legacy procedural languages like C or Fortran, which support true rectangular contiguous multidimensional arrays (e.g., matrix[row, col]), Java's architects chose the nested "array of arrays" approach to keep the JVM memory allocation logic profoundly simple and strictly object-oriented. Causal Reasoning: The outermost dimension size must be declared first (Statement 2) because the JVM must know precisely how many reference pointers to allocate for the primary array object in the Heap. Without the base row count, the foundational pointer structure physically cannot be built.]
✅ Correct Answer: A
🎯 Quick Answer:
The correct combination is 1 and 2. Statement 3 is incorrect because Java treats each inner array as an entirely separate object dynamically allocated in the Heap, meaning they are widely scattered and rarely contiguous in physical memory.
Concept Definition: A jagged array is a multi-dimensional array where the constituent sub-arrays can possess varying lengths, rather than forming a perfect, uniform rectangular matrix.
Structural Breakdown: Instantiating a jagged array requires syntax like 'int[