Home » JAVA Programming » Exceptions » Question
  1. What is the output of this program?
    public class ExceptionHandling_Example
    {
    public static void main(String args[])
    {
    try
    {
    int array[] = {10, 20,30 , 40, 50};
    for (int K = 0; K < 5; ++K)
    System.out.print(array[K]);
    int p = 1/0;
    }
    catch(ArrayIndexOutOfBoundsException e)
    {
    System.out.print("L");
    }
    catch(ArithmeticException e)
    {
    System.out.print("U");
    }
    }
    }
    1. 1020304050
    2. 10203050
    3. 1020304050U
    4. 20304050U
    5. 304050U
Correct Option: C

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 U is printed after 1020304050



Your comments will be displayed only after manual approval.