Menu
Question Index
...

What will be the output of the following program?

public class AllDimensionArrays {
    public static void main(String[] args) {
        int[] a1d = {};
        int[] b1d = {1, 3};
        int[][] a2d = {};
        int[][] b2d = {{}};
        int[][] c2d = {{1, 2}, {5}};
        System.out.print(a1d.length + " " + b1d.length + " ");
        System.out.print(a2d.length + " " + a2d[0].length + " " + b2d.length + " " + b2d[0].length + " ");
        System.out.print(c2d.length + " " + c2d[0].length + " " + c2d[1].length);
    }
}


0 2 0 0 1 0 2 2 1
0 2 0 0 0 0 2 2 1
Some other output
ArrayIndexOutOfBoundsException
Compilation Error or Runtime Error for some other reason.

Doubts

Problems

Topic: Java Array Initialization

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App