Hi, I am studying for SJCP 1.5. I have a study book and do not understand a question/answer. Can someone please help me. Here is the question:
Given:
import java.io.*;
class Master {
String doFileStuff() 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 code here
}
Does the following compile correctly and produce the output "b" when inserted at // Insert code here
String doFileStuff() throws NumberFormatException, FileNotFoundException {
return "b";
}
The answer says it works but I answered it did not since NumberFormatException is not thrown by Master so it is not a valid override.
Can someone help me understand?
thanks
Harry