| Author |
OCP JP Practice Exam 2 #29
|
Jelo Nehuptra
Ranch Hand
Joined: Oct 08, 2011
Posts: 36
|
|
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;}
|
 |
Harsha Smith
Ranch Hand
Joined: Jul 18, 2011
Posts: 287
|
|
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
G. void think() throws RunTimeException
|
 |
Jeffrey Tian
Ranch Hand
Joined: Jun 02, 2010
Posts: 34
|
|
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.
|
 |
Dan Drillich
Ranch Hand
Joined: Jul 09, 2001
Posts: 1123
|
|
Right, C & F are correct since Feynman().think() is now a brand new method.
Regards,
Dan
|
William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
|
 |
Jelo Nehuptra
Ranch Hand
Joined: Oct 08, 2011
Posts: 36
|
|
Jeffrey Tian wrote:
I just finished this exam and didn't find the problem. The correct answers should be C & F.
What do you mean you didn't find the problem? It clearly says on pp. 210 that "B, C, D, and F are correct."
|
 |
Dan Drillich
Ranch Hand
Joined: Jul 09, 2001
Posts: 1123
|
|
Jelo,
Not sure what the book says, but the following doesn't compile -
On
We get -
Regards,
Dan
|
 |
Jeffrey Tian
Ranch Hand
Joined: Jun 02, 2010
Posts: 34
|
|
Jelo Nehuptra wrote:
Jeffrey Tian wrote:
I just finished this exam and didn't find the problem. The correct answers should be C & F.
What do you mean you didn't find the problem? It clearly says on pp. 210 that "B, C, D, and F are correct."
Sorry for any misunderstanding. I should have said that I didn't find the problem you mentioned. The Answer given by the book is wrong.
|
 |
Harsha Smith
Ranch Hand
Joined: Jul 18, 2011
Posts: 287
|
|
|
main method "throws Exception" clause wasn't printed,I guess.
|
 |
 |
|
|
subject: OCP JP Practice Exam 2 #29
|
|
|