Bird
0
0

Find the error in this code snippet:

medium📝 Debug Q7 of 15
Java - Exception Handling

Find the error in this code snippet:

public void open() throws FileNotFoundException {
    // code
}
public void start() throws IOException {
    open();
}
Astart() must declare FileNotFoundException explicitly
Bstart() correctly declares IOException, no error
Copen() cannot throw FileNotFoundException
DFileNotFoundException is unchecked, no need to declare
Step-by-Step Solution
Solution:
  1. Step 1: Understand exception hierarchy

    FileNotFoundException is a subclass of IOException.
  2. Step 2: Analyze start() declaration

    Declaring throws IOException covers all its subclasses including FileNotFoundException.
  3. Final Answer:

    start() correctly declares IOException, no error -> Option B
  4. Quick Check:

    Superclass exception declaration covers subclasses [OK]
Quick Trick: Superclass exceptions cover subclass exceptions in throws [OK]
Common Mistakes:
  • Thinking all exceptions must be declared explicitly
  • Confusing checked and unchecked exceptions
  • Assuming subclass exceptions need separate declaration

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes