Menu
Topics Index
...
`

Sections


If you need explanation Read this topic

If you need Answer Take test on this topic

Sections
What will be the output of the following program?
public class Sections {
    public static void main(String args[]) {
        char sections[] = {'A', 'B', 'C', 'D'};
        try {
            for (int i = 0; i <= sections.length; i++)
                System.out.print(sections[i] + " ");
        } catch (Exception e) {
            System.out.print(e);
        }
    }
}

A. A B C D
B. A B C D java.lang.ArrayIndexOutOfBoundsException: 4
C. Compilation Error
D. Runtime Error for some other reason
Topic: Java Built In Exceptions Checked Exceptions, Unchecked Exceptions

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

ans B length is 4 and starts from 0 so at i=4 no element to print so it will throws arrayindexoutofbound exception

Posted by Bheema Reddy    2014-02-12 03:38:29


Congratulations Bheema Reddy. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-02-13 04:10:21


© meritcampus 2019

All Rights Reserved.

Open In App