Which of the following is a checked exception in Java?

Java MCQ: Which of the following is a checked exception in Java?

a) NullPointerException
b) IOException
c) ArithmeticException
d) ArrayIndexOutOfBoundsException

Answer:

b) IOException

Explanation:

In Java, exceptions are categorized into two main types: checked exceptions and unchecked exceptions. Checked exceptions are exceptions that must be either caught or declared in the method signature using the throws keyword. These exceptions are checked at compile time.

IOException is an example of a checked exception. It occurs when an input-output operation fails or is interrupted, such as when a file cannot be found or read. The compiler requires that such exceptions be handled or declared, ensuring that the programmer anticipates and deals with these potential issues.

Unchecked exceptions, such as NullPointerException, ArithmeticException, and ArrayIndexOutOfBoundsException, do not require explicit handling because they indicate programming errors that can often be avoided with better coding practices.

Reference links:

https://www.rameshfadatare.com/learn-java-programming/
https://www.javaguides.net/p/java-tutorial-learn-java-programming.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top