• 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

Flow Control Question from SCJP Study Guide Book

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm reading the SCJP Study Guide book by Sierra and Bates. I had a question about one of the practice questions in the book. In chapter 5 practice question 15 is as follows:


And given the following four code fragments:
I. public static void main(String[] args) {
II. public static void main(String[] args) throws Exception {
III. public static void main(String[] args) throws IOException {
IV. public static void main(String[] args) throws RuntimeException {

if the four fragments are inserted independently at line 4, which are true? (Choose all that apply.)
A - C are incorrect and I understand why.
D Some, but not all, will compile and execute and throw an exception. (True statement and I understand why)
E When considering fragments II, III, and IV, of those that will compile, adding a try/catch block around line 6 will cause compilation to fail.

The book says that E is incorrect because it's okay to both handle and declare an exception. However, putting a try/catch block around line 6 is putting it around the closing curly brace of the class, which would cause a compile error. Am I missing something here? Or am I just interpreting the question wrong? Thanks in advance for your help.
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you please post the options
 
Jarred Olson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The only answer that I'm questioning is the answer E which is listed in the original post.
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is an error in the question, it should read:
E - When considering fragments II, III and IW, of those that will compile, adding a try/catch block around line 4 will cause compile to fail.

I really wish there was a proper erratum for this book (mine is SCJP6), it has quite a few errors.
 
We find this kind of rampant individuality very disturbing. But not this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic