• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OCP JP Practice Exam 2 #29

 
Ranch Hand
Posts: 36
jQuery Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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;}
 
Ranch Hand
Posts: 287
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 37
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
jQuery Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 37
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
main method "throws Exception" clause wasn't printed,I guess.
 
Is this the real life? Is this just fantasy? Is this a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic