File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OCP JP Practice Exam 2 #29

 
Jelo Nehuptra
Ranch Hand
Posts: 36
Java jQuery Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, C & F are correct since Feynman().think() is now a brand new method.

Regards,
Dan
 
Jelo Nehuptra
Ranch Hand
Posts: 36
Java jQuery Netbeans IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1183
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jelo,

Not sure what the book says, but the following doesn't compile -


On


We get -


Regards,
Dan


 
Jeffrey Tian
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 287
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
main method "throws Exception" clause wasn't printed,I guess.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic