I'm not sure I understand this concept well enough. In Chapter 5 of the
SCJP 5 book (yes, I have access to v. 6 as well) question 8 asks:
Given:
And the following three possible changes:
C1. Declare that main() throws an exception
C2. Declare that Ping.getInt() throws an exception
C3. Wrap the invocation of getInt() in a try/catch block
Which change(s) allow the code to compile? (Choose all that apply)
A. Just C1
B. Just C2
C. Just C3
D. Both C1 and C2 are required
E. Both C1 and C3 are required
F. Both C2 and C3 are required
G. All three changes are required.
I got the answer wrong, so tried out the example for myself. My understanding is:
A. Since Ping extends Utils and Ping.getInt() has the same signature as Utils.getInt(), getInt() is an overridden method
B. Overridden methods are determined by the actual object (Ping) at runtime
C. Overridden methods can throw the same, less restrictive, or no exceptions
Therefore, the compiler shouldn't care that Ping.getInt() doesn't throw any exceptions... right? But it does.
Where am I mistaken?
BTW, the book says that only A and C are correct, yet if you take the statement "What changes allow the code to compile? Choose all that apply" at face value, answers D, E, F, and G are also true.