posted 11 years ago
The question is from the BB && KS Practice Exams book
29. Given that:
Exception is the superclass of IOException, and
IOException is the superclass of FileNotFoundException, and
Which of the following methods, inserted independently at line 11, compiles? (Choose all
that apply.)
A. void think() throws Exception { }
B. void think() throws FileNotFoundException { }
C. public void think() { }
D. protected void think() throws IOException { }
E. private void think() throws IOException { }
F. void think() { int x = 7/0; }
Answer (for Objective 1.4):
B, C, D, and F are correct. It’s legal for overridden methods to have less restrictive
access modifiers, to have fewer or narrower checked exceptions, and to have unchecked
exceptions. (Note: Of course, F would throw an exception at runtime.)
A is incorrect because Exception is broader. E is incorrect because private is more
restrictive.
________________________________________
I think there is something wrong with the answer
B does not compile because FileNotFoundException is not caught in the main method
D does not compile because IOException is not caught in the main method
Can someone confirm my supposition, or I am missing something?