Why is it that the answer BCDF when B&D declares checked exception and the main method doesn't declare nor handle it?
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;}
A is wrong because the overriding method must not throw new or broader checked exceptions.
E is wrong because you are reducing the visibility of the method.
B is correct because FileNotFoundException is the sub class of IO Exception(Narrow Exception)
C is correct because the overriding method may throw a fewer or no exceptions
D is correct because you aren't messing with the visibility of the method
F is correct for obvious reasons.
Additionally 'G' is also correct if exists. something like
Jelo Nehuptra wrote:Why is it that the answer BCDF when B&D declares checked exception and the main method doesn't declare nor handle it?
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;}
I just finished this exam and didn't find the problem. The correct answers should be C & F.