🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Java Arrays: all 10 questions

Quiz: Java Arrays · Question 10 of 10

What does this print? (code)

What does this print?

public class Main {
    public static void main(String[] args) {
        int[][] j = new int[3][];
        j[0] = new int[2];
        j[1] = new int[5];
        j[2] = new int[1];
        System.out.println(j.length + " " + j[1].length);
    }
}
  1. A.5 3
  2. B.3 3
  3. C.8 5
  4. D.3 5
Answer & explanation

Correct answer: 3 5

A 2D array is an array of arrays, so each row can have its own length (a jagged array). There are 3 rows, and row 1 has 5 columns.

Can you get the rest right without peeking?

Take the timed Quiz: Java Arrays quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →