Exceptions(Java Program ) Questions and Answers

Question 1. Which exception is thrown when divide by zero statement executes?
  1.    NumberFormatException
  2.    ArithmeticException
  3.    NullPointerException
  4.    None of these
Explanation:-
Answer: Option B. -> ArithmeticException

Question 2. In which of the following package Exception class exist?
  1.    java.util
  2.    java.file
  3.    java.io
  4.    java.lang
  5.    java.net
Explanation:-
Answer: Option D. -> java.lang

Question 3. Exception generated in try block is caught in ........... block.
  1.    catch
  2.    throw
  3.    throws
  4.    finally
Explanation:-
Answer: Option A. -> catch

Question 4. Which keyword is used to explicitly throw an exception?
  1.    try
  2.    throwing
  3.    catch
  4.    throw
Explanation:-
Answer: Option D. -> throw

Question 5. The class at the top of exception class hierarchy is .................
  1.    ArithmeticException
  2.    Throwable
  3.    Object
  4.    Exception
Explanation:-
Answer: Option B. -> Throwable

Question 6. Which keyword is used to specify the exception thrown by method?
  1.    catch
  2.    throws
  3.    finally
  4.    throw
Explanation:-
Answer: Option B. -> throws

Question 7. Which of the following blocks execute compulsorily whether exception is caught or not.
  1.    finally
  2.    catch
  3.    throws
  4.    throw
Explanation:-
Answer: Option A. -> finally

Question 8. What happen in case of multiple catch blocks?
  1.    Either super or subclass can be caught first.
  2.    The superclass exception must be caught first.
  3.    The superclass exception cannot caught first.
  4.    None of these
Explanation:-
Answer: Option C. -> The superclass exception cannot caught first.

Question 9. What is the output of the following program code?
public class Test{
public static void main(String args[]){
try{
int i;
return;
}
catch(Exception e){
System.out.print("inCatchBlock");
}
finally{
System.out.println("inFinallyBlock");
}
}
}
  1.    inCatchBlock
  2.    inCatchBlock inFinallyBlock
  3.    inFinallyBlock
  4.    The program will return without printing anything
Explanation:-
Answer: Option C. -> inFinallyBlock

Question 10. Which exception is thrown when an array element is accessed beyond the array size?
  1.    ArrayElementOutOfBounds
  2.    ArrayIndexOutOfBoundsException 
  3.    ArrayIndexOutOfBounds
  4.    None of these
Explanation:-
Answer: Option B. -> ArrayIndexOutOfBoundsException