The following code is a question from K&B's book.
Which, inserted independently at // insert code here, will compile, and produce the output b?
A.
String doFileStuff() { return "b"; }
B. String doFileStuff() throws IOException { return "b"; }
C. String doFileStuff(int x) throws IOException { return "b"; }
D. String doFileStuff() throws FileNotFoundException { return "b"; }
E. String doFileStuff() throws NumberFormatException { return "b"; }
F. String doFileStuff() throws NumberFormatException,
FileNotFoundException { return "b"; }
In my first attempt I chose "D" but the correct answers are "A","D","E","F".
Can anyone give me some more detais about the correct answers ?
Would be highly appreciated if you could also clarify me the following related questions :
1 - Supposing that doFileStuff() method was declared in an interface and throws an IOException, is the concrete implementer class obligated to throw the exception too ?
Can a concrete class implement an interface or extend a super class (abstract or not) by adding more exceptions than declared in super class or interface ?