Exceptions


  1. Which of these statements is incorrect?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    try must be followed by either catch or finally block.


  1. What is the output of this program?
    public class Result 
    {
    public static void main(String args[])
    {
    try
    {
    int p = 0;
    int q = 11;
    int s = q / p;
    System.out.print("Hello");
    }
    catch(Exception e)
    {
    System.out.print("Java");
    }
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    Java



  1. What is the output of this program?
    public  class Result 
    {
    public static void main(String args[])
    {
    try
    {
    int p = 2;
    int q = 9;
    int s = p / q;
    System.out.print("First");
    }
    catch(Exception e)
    {
    System.out.print("Second");
    }
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    First


  1. What is the output of this program?
    public class Result 
    {
    public static void main(String args[])
    {
    try
    {
    int num = 0;
    int num0 = 23;
    int num1 = num0 / num;
    System.out.print(+num1);
    }
    catch(Exception e)
    {
    System.out.print("Interview Mania");
    }
    finally
    {
    System.out.print(" Finally executed...");
    }
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    finally block is always executed after tryblock, no matter exception is found or not. catch block is executed only when exception is found. Here divide by zero exception is found hence both catch and finally are executed.



  1. Which of these exceptions will occur if we try to access the index of an array beyond its length?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    ArrayIndexOutOfBoundsException is a built in exception that is caused when we try to access an index location which is beyond the length of an array.