aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes OCP JP Practice Exam 2 #29 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "OCP JP Practice Exam 2 #29" Watch "OCP JP Practice Exam 2 #29" New topic
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: 1174
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: 1174
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OCP JP Practice Exam 2 #29