Home » JAVA Programming » Exceptions » Question
  1. What is the output of this program?
    public class Array_Exception 
    {
    public static void main(String args[])
    {
    try
    {
    int p = args.length;
    int q = 12 / p;
    System.out.print(p);
    try
    {
    if (p == 1)
    p = p / p - p;
    if (p == 2)
    {
    int []s = {1};
    s[10] = 8;
    }
    }
    catch (ArrayIndexOutOfBoundException e)
    {
    System.out.println("First");
    }
    }
    catch (ArithmeticException e)
    {
    System.out.println("Second");
    }
    }
    }
    1. Compilation Error
    2. Runtime Error
    3. First
    4. Second
    5. None of these
Correct Option: B

Because we can’t go beyond array limit



Your comments will be displayed only after manual approval.