Multiple choice technology programming languages

import java.io.*; class Master { String doFileWork() throws FileNotFoundException { return "a"; } } class Slave extends Master { public static void main(String[] args) { String s = null; try { s = new Slave().doFileStuff(); } catch ( Exception x) { s = "b"; } System.out.println(s); } //insert a codeline } Choose the correct answers :

  1. String doFileWork() { return "b"; }

  2. String doFileWork() throws IOException ( return "b"; }

  3. String doFileWork(int x) throws IOException { return "b"; }

  4. String doFileWork() throws FileNotFoundException { return "b"; }

  5. String doFileWork() throws NumberFormatException { return "b"; }

  6. String doFileWork() throws NumberFormatException, FileNotFoundException { return "b"; }

Reveal answer Fill a bubble to check yourself
A,D,E,F Correct answer
Explanation

When overriding a method, the overriding method cannot throw broader or new checked exceptions. It can only throw the same exceptions, subclasses of those exceptions, or unchecked exceptions (RuntimeException). Options A (no exception), D (same FileNotFoundException), E and F (NumberFormatException is unchecked/RuntimeException) are valid. Option B (IOException is broader than FileNotFoundException) violates this rule. Option C is not an override (different parameter list - overloaded method).