• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Flow Control Question from SCJP Study Guide Book

 
Jarred Olson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • 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.
 
Himanshu Kansal
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please post the options
 
Jarred Olson
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The only answer that I'm questioning is the answer E which is listed in the original post.
 
Jason Irwin
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic