• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 6 Exceptions, Question 11 (Java OCA 8 Programmer I Study Guide, Sybex)

 
Jakub Turoboś
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the output of the following program?


A. 12, followed by a stack trace for a NumberFormatException
B. 124, followed by a stack trace for a NumberFormatException
C. 12456
D. 12456
E. 1256, followed by a stack trace for a NumberFormatException
F. The code does not compile.
G. An uncaught exception is thrown.

Answer at the end is A, but should be A,G. As mentioned in explanation - "... Line 7 throws a NumberFormatException. It isn’t caught, so ..."
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That question doesn't say "choose all that apply" which means you are supposed to choose the best single answer. Choice A includes throwing a specific stack trace so it is the best answer. If the code threw a NullPointerException say, then the answer would be choice G (and not choice A.)

Also, I added the word "Wiley" to the subject of both your threads. There are multiple OCA 8 study guides out now so we want it to be obvious to other posters which threads are about which. I of course knew because I recognized our questions .
 
Jakub Turoboś
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:That question doesn't say "choose all that apply" which means you are supposed to choose the best single answer. Choice A includes throwing a specific stack trace so it is the best answer. If the code threw a NullPointerException say, then the answer would be choice G (and not choice A.)

Also, I added the word "Wiley" to the subject of both your threads. There are multiple OCA 8 study guides out now so we want it to be obvious to other posters which threads are about which. I of course knew because I recognized our questions .


I guess I have to read the questions more carefully. Thanks again ;)
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:If the code threw a NullPointerException say, then the answer would be choice G (and not choice A.)

That's not 100% correct If a NullPointerException was thrown inside the try block, the NullPointerException would definitely be caught by the catch block on line 9 and thus it would not have been an uncaught exception. So an ArrayIndexOutOfBoundsException would have been a better example for choice G
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
Jeanne Boyarsky wrote:If the code threw a NullPointerException say, then the answer would be choice G (and not choice A.)

That's not 100% correct If a NullPointerException was thrown inside the try block, the NullPointerException would definitely be caught by the catch block on line 9 and thus it would not have been an uncaught exception. So an ArrayIndexOutOfBoundsException would have been a better example for choice G

Heh. You are right. I didn't actually read the question before replying. Just the answers.
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:I didn't actually read the question before replying. Just the answers.

To all OCA exam aspirants: don't try this at the actual exam
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic