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[] = {1, 2,3 , 4, 5};
    for (int k = 0; k < 7; ++k)
    System.out.print(array[k]);
    }
    catch(ArrayIndexOutOfBoundsException e)
    {
    System.out.print("5");
    }
    }
    }
    1. 123455
    2. 123
    3. 12345
    4. 123450
    5. 120345
Correct Option: A

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



Your comments will be displayed only after manual approval.