aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Flow Control Question from SCJP Study Guide Book Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Flow Control Question from SCJP Study Guide Book" Watch "Flow Control Question from SCJP Study Guide Book" New topic
Author

Flow Control Question from SCJP Study Guide Book

Jarred Olson
Ranch Hand

Joined: Jul 31, 2009
Posts: 37
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

Joined: Jul 05, 2009
Posts: 257
Could you please post the options


Experience and talent are independent of age
Jarred Olson
Ranch Hand

Joined: Jul 31, 2009
Posts: 37
The only answer that I'm questioning is the answer E which is listed in the original post.
Jason Irwin
Ranch Hand

Joined: Jun 09, 2009
Posts: 327
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.


SCJP6
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Flow Control Question from SCJP Study Guide Book