Home » JAVA Programming » Exceptions » Question
  1. What is the output of this program?
    public class exception_Example 
    {
    public static void main(String args[])
    {
    try
    {
    int array[] = {11, 21,31 , 41, 51};
    for (int k = 0; k < 5; ++k)
    System.out.print(array[k]);
    int p = 1/0;
    }
    catch(ArrayIndexOutOfBoundsException e)
    {
    System.out.print("I");
    }
    catch(ArithmeticException e)
    {
    System.out.print("L");
    }
    }
    }
    1. 1121314151L
    2. 112131
    3. 1121314151U
    4. 112131451
    5. L1121314151
Correct Option: A

There can be more than one catch of a single try block. Here Arithmetic exception occurs instead of Array index out of bound exception hence L is printed after 1121314151.



Your comments will be displayed only after manual approval.