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[] = {5,6,7,8};
    for (int K = 0; K < 7; ++K)
    System.out.print(array[K]);
    }
    catch(ArrayIndexOutOfBoundsException e)
    {
    System.out.print("9");
    }
    }
    }
    1. Compilation Error
    2. 56789
    3. Runtime Error
    4. 12345
    5. 56780
Correct Option: B

When array index goes out of bound then ArrayIndexOutOfBoundsException exception is thrown by the system.



Your comments will be displayed only after manual approval.