Home » JAVA Programming » Exceptions » Question
  1. What is the output of this program?
    public class exceptionHandling_Example
    {
    public static void main(String args[])
    {
    try
    {
    throw new NullPointerException ("Hello");
    System.out.print("First");
    }
    catch(ArithmeticException e)
    {
    System.out.print("Second");
    }
    }
    }
    1. NullPointerException
    2. ArithmeticException
    3. Second
    4. First
    5. Runtime Error
Correct Option: E

try block is throwing NullPointerException but the catch block is used to counter Arithmetic Exception. Hence NullPointerException occurs since no catch is there which can handle it, runtime error occurs.

error: unreachable statement
System.out.print("First");



Your comments will be displayed only after manual approval.