Q: Which of the following statements are true?
The following is NOT correct based on the test.
An overriding method can declare that it throws a wider spectrum of checked exceptions than the method it is overriding.
But isn't this correct?
The following example showcases this. Where the overriding method is in fact throwing a wider spectrum of checked exceptions and compiles fine.
Am I missing something, misread the question / answer? Please advice. Thank you.
Code: Select all
import java.io.IOException;
public class App extends Haha {
@Override
void test() throws IOException, InterruptedException, NoSuchMethodException, IllegalAccessException {
}
}
class Haha {
void test() throws Exception {
}
}