oop

18. Overriding & Exceptions: The Strict Rules

Analyze the code, write your predicted output, and then reveal the solution.

Scenario

Can an overriding method throw more exceptions than the parent? No. This practice explores the rules of checked vs unchecked exceptions in inheritance.

Code Block
import java.io.*; class Super { void process() throws IOException { System.out.println("Super processing"); } } class Sub extends Super { @Override void process() throws FileNotFoundException { // Valid: Subclass of IOException System.out.println("Sub processing"); } // void process() throws Exception { } // ERROR: Broader than IOException } public class Main { public static void main(String[] args) throws IOException { Super obj = new Sub(); obj.process(); } }
Take Your Shot
Predicted Output

Type exactly what you think will be printed in the console.

18. Overriding & Exceptions: The Strict Rules | DevExCode