| Author |
K&B book self test 15 on page 409
|
John Stark
Ranch Hand
Joined: Jul 19, 2011
Posts: 165
|
|
I am a bit confused about answer B:
... adding a try/catch block around line 6 will cause compilation to fail
Line 6 is the last line of the code just containing the closing bracket of the class. Where is the try/catch supposed to go?
Thanks,
John
|
 |
Suhas Mandrawadkar
Ranch Hand
Joined: Jul 21, 2007
Posts: 72
|
|
I don't have KB book around
Please be more specific with question.
|
Regards, Suhas S. Mandrawadkar.
Certifications: SCJP 6, SCWCD 5, Oracle WebLogic Server Administrator, OCE Java EE 6 EJB Developer
|
 |
John Stark
Ranch Hand
Joined: Jul 19, 2011
Posts: 165
|
|
Given:
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. All four will compile and execute without exception.
B. All four will compile and execute and throw an exception.
C. Some, but not all, will compile and execute without exception.
D. Some, but not all, will compile and execute and throw an exception.
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.
In the answer it says:
E is incorrect because it's okay to both handle and declare an exception.
I just don't understand what 'adding a try/catch block around line 6' means. How would that look like?
Thanks,
John
|
 |
Scotty Mitchell
Ranch Hand
Joined: Aug 09, 2011
Posts: 46
|
|
I'm going to assume that this means within the main method there is a try-catch construct to check for division by zero. That would be "handling" the exception since there will be a divide by zero exception in this case. I believe something like this would be what they are talking about:
|
 |
Christian Joseph
Ranch Hand
Joined: Jan 07, 2011
Posts: 43
|
|
hehe where on the same topic.... hmm, i dunno yet the answer
but the above post solve your problem about the QUESTION on the self Test
|
 |
John Stark
Ranch Hand
Joined: Jul 19, 2011
Posts: 165
|
|
Hm yes, I found this in the thread 'Compiling errata for K&B, SCJP 6'
John Summers wrote:page 409 question 15
a)says "at line 4" and should say "at line 2".
b)in option E I think it should say "line 4" not "line 6"
So maybe it is just an error?
John
|
 |
Scotty Mitchell
Ranch Hand
Joined: Aug 09, 2011
Posts: 46
|
|
John Stark wrote:Hm yes, I found this in the thread 'Compiling errata for K&B, SCJP 6'
John Summers wrote:page 409 question 15
a)says "at line 4" and should say "at line 2".
b)in option E I think it should say "line 4" not "line 6"
So maybe it is just an error?
John
I think perhaps after you write the code including the try and catch block you end up having the line you want inspected at line 6
|
 |
John Stark
Ranch Hand
Joined: Jul 19, 2011
Posts: 165
|
|
|
Ha ha, that's right.
|
 |
 |
|
|
subject: K&B book self test 15 on page 409
|
|
|