Bird
0
0

Which of the following method signatures correctly declares a checked exception?

easy📝 Syntax Q3 of 15
Java - Exception Handling
Which of the following method signatures correctly declares a checked exception?
Apublic void readFile() throws NullPointerException
Bpublic void readFile() throws IOException
Cpublic void readFile() throws Error
Dpublic void readFile() throws RuntimeException
Step-by-Step Solution
Solution:
  1. Step 1: Identify checked exceptions in options

    IOException is a checked exception and must be declared.
  2. Step 2: Check other options

    NullPointerException, Error, and RuntimeException are unchecked or errors, so no need to declare.
  3. Final Answer:

    public void readFile() throws IOException -> Option B
  4. Quick Check:

    Checked exceptions require throws declaration [OK]
Quick Trick: Only checked exceptions need throws declaration [OK]
Common Mistakes:
  • Declaring unchecked exceptions with throws
  • Confusing Error with Exception
  • Missing throws for checked exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes