OOP Using Java •
MCQ • Exception Handling
Most Important 30 Objective Question - Exception Handling
Q1. What is an exception in Java?
A) A normal statement
B) An event that interrupts normal program flow
C) A loop
D) A package
Answer: B) An event that interrupts normal program flow
Explanation:An exception is an unwanted event that occurs during program execution and disturbs the normal flow.
Q2. Which keyword is used to handle exceptions?
A) catch
B) try
C) throw
D) All of these
Answer: D) All of these
Explanation:Java uses try, catch, throw, throws, and finally for exception handling.
Q3. Which block must be written before catch block?
A) finally
B) try
C) throw
D) throws
Answer: B) try
Explanation:The try block contains code that may generate an exception and must come before catch.
Q4. Which block is used to handle the exception?
A) try
B) catch
C) throw
D) throws
Answer: B) catch
Explanation:The catch block handles the exception generated inside the try block.
Q5. Which keyword is used to manually throw an exception?
A) throws
B) catch
C) throw
D) final
Answer: C) throw
Explanation:The throw keyword is used to create and throw an exception manually.
Q6. Which keyword is used to declare exceptions?
A) throw
B) throws
C) catch
D) final
Answer: B) throws
Explanation:The throws keyword is used in method declaration to indicate possible exceptions.
Q7. Which block always executes whether exception occurs or not?
A) try
B) catch
C) finally
D) throw
Answer: C) finally
Explanation:The finally block always executes and is used for cleanup work like closing files.
Q8. Which class is the parent of all exception classes?
A) String
B) Throwable
C) System
D) Object
Answer: B) Throwable
Explanation:Throwable is the root class for both Exception and Error classes.
Q9. Which of the following is a checked exception?
A) ArithmeticException
B) NullPointerException
C) IOException
D) ArrayIndexOutOfBoundsException
Answer: C) IOException
Explanation:Checked exceptions are checked at compile time. IOException is a checked exception.
Q10. Which of the following is an unchecked exception?
A) IOException
B) SQLException
C) ArithmeticException
D) ClassNotFoundException
Answer: C) ArithmeticException
Explanation:Unchecked exceptions occur at runtime and are not checked by compiler.
Q11. Which exception occurs when dividing by zero?
A) NullPointerException
B) ArithmeticException
C) IOException
D) NumberFormatException
Answer: B) ArithmeticException
Explanation:Division by zero in integer operations causes ArithmeticException.
Q12. Which exception occurs when accessing null object?
A) IOException
B) NullPointerException
C) ArithmeticException
D) SQLException
Answer: B) NullPointerException
Explanation:If we try to use a null object reference, NullPointerException occurs.
Q13. Which exception occurs when array index exceeds limit?
A) ArrayIndexOutOfBoundsException
B) IOException
C) ClassNotFoundException
D) NumberFormatException
Answer: A) ArrayIndexOutOfBoundsException
Explanation:This exception occurs when accessing an invalid array index.
Q14. Can we use multiple catch blocks with one try block?
A) No
B) Yes
C) Only once
D) Only in main()
Answer: B) Yes
Explanation:Java allows multiple catch blocks to handle different exceptions.
Q15. User-defined exceptions are created using:
A) interface
B) inheritance
C) package
D) loop
Answer: B) inheritance
Explanation:User-defined exceptions are created by extending Exception class.
Q16. Which block can contain another try block inside it?
A) switch
B) Nested try
C) static block
D) package
Answer: B) Nested try
Explanation:A try block inside another try block is called a nested try block.
Q17. Which statement is true about finally block?
A) It runs only when exception occurs
B) It runs only when no exception occurs
C) It always executes
D) It is optional and never runs
Answer: C) It always executes
Explanation:The finally block executes whether an exception occurs or not.
Q18. Which is not a subclass of Exception?
A) IOException
B) ArithmeticException
C) Error
D) NullPointerException
Answer: C) Error
Explanation:Error and Exception both extend Throwable, but Error is not a subclass of Exception.
Q19. Which of the following belongs to runtime exception?
A) IOException
B) SQLException
C) NullPointerException
D) ClassNotFoundException
Answer: C) NullPointerException
Explanation:Runtime exceptions are unchecked exceptions. NullPointerException is one of them.
Q20. Which exception occurs when a string cannot be converted into number?
A) NumberFormatException
B) ArithmeticException
C) IOException
D) SQLException
Answer: A) NumberFormatException
Explanation:If invalid numeric text is converted using Integer.parseInt(), NumberFormatException occurs.
Q21. Which keyword is used to rethrow an exception?
A) catch
B) throw
C) throws
D) finally
Answer: B) throw
Explanation:The throw keyword can be used again inside catch block to rethrow an exception.
Q22. Which statement is correct for checked exceptions?
A) Checked at runtime only
B) Ignored by compiler
C) Checked at compile time
D) Never handled
Answer: C) Checked at compile time
Explanation:Checked exceptions must be handled or declared using throws.
Q23. Which statement is correct for unchecked exceptions?
A) Checked at compile time
B) Checked at runtime
C) Must use throws
D) Must use finally
Answer: B) Checked at runtime
Explanation:Unchecked exceptions are not checked by compiler and occur during runtime.
Q24. Which keyword is used after try block?
A) import
B) class
C) catch
D) extends
Answer: C) catch
Explanation:The catch block is generally written immediately after try block.
Q25. Which of the following is not an exception handling keyword?
A) try
B) catch
C) throw
D) extends
Answer: D) extends
Explanation:extends is used for inheritance, not exception handling.
Q26. Which class is used for user-defined exception?
A) String
B) Exception
C) Scanner
D) Object
Answer: B) Exception
Explanation:User-defined exceptions are generally created by extending Exception class.
Q27. What is the full form of JVM?
A) Java Variable Machine
B) Java Virtual Machine
C) Java Verified Method
D) Java Visual Model
Answer: B) Java Virtual Machine
Explanation:JVM runs Java bytecode and helps Java become platform independent.
Q28. Which of the following is an Error?
A) StackOverflowError
B) IOException
C) SQLException
D) ArithmeticException
Answer: A) StackOverflowError
Explanation:StackOverflowError is an Error, not an Exception.
Q29. Which method declaration is correct?
A) void test() throws IOException
B) void test() throw IOException
C) void test() catch IOException
D) void test() finally IOException
Answer: A) void test() throws IOException
Explanation:throws is used in method declaration for checked exceptions.
Q30. Exception handling improves:
A) Program reliability
B) Only speed
C) Only graphics
D) Only memory
Answer: A) Program reliability
Explanation:Exception handling helps prevent abnormal termination and improves reliability of programs.
Google AdSense Ad Placement Here 📢