Menu
Question Index
...

What will be the output of the following program?

public class Family {
    public static void main(String args[]) {
        String array[] = new String[-3];
        array[0] = "father";
        array[1] = "mother";
        array[2] = "children";
        String str = "";
        for (String element : array) {
            str += element + "";
        }
        System.out.print(str);
    }
}


father mother children
Runtime Error because of java.lang.NullPointerException
Runtime Error because of java.lang.ArrayIndexOutOfBoundsException
Runtime Error because of java.lang.NegativeArraySizeException
Runtime Error because of some other reason

Doubts

Problems

Topic: Java Built In Exceptions Checked Exceptions, Unchecked Exceptions

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App