Multiple choice technology

Consider the code below: arr[0] = new int[4]; arr[1] = new int[3]; arr[2] = new int[2]; arr[3] = new int[1]; for( int n = 0; n < 4; n++ ) System.out.println( /* what goes here? */ );

  1. arr[n].length();

  2. arr.size;

  3. arr.size-1;

  4. arr[n].length;

Reveal answer Fill a bubble to check yourself
D Correct answer
Explanation

In Java, arrays use the length property rather than a method length() or size property to determine their size. Since arr[n] refers to a 1D integer array, arr[n].length correctly retrieves its size.