| Author |
Question From JQuest Mock Exam...
|
Barbara Dyer-Bennet
Greenhorn
Joined: Sep 14, 2000
Posts: 10
|
|
 <HTML> What letters are written to the standard output with the following code? 1.����class Unchecked { 2.�������public static void main(String[] args) { 3.����������try { 4.�������������method(); 5.����������} catch(Exception e) {} 6.�������} 7.�������static void method() { 8.����������try { 9.�������������wrench(); 10.������������System.out.println("a"); 11.���������}catch(ArithmeticException e) { 12.������������System.out.println("b"); 13.���������}finally { 14.������������System.out.println("c"); 15.���������} 16.���������System.out.println("d"); 17.������} 18.������static void wrench() { 19.���������throw new NullPointerException(); 20.������} 21.���} Select all valid answers(correct answers are blue): a.����"a" b.����"b" c.����"c" d.����"d" Here's what I thought... that both c and d would be printed, because the program would execute line 16 after the last finally block. Why is this so? Thanks in advance, Barbara</BODY> </HTML> [This message has been edited by Barbara Dyer-Bennet (edited September 16, 2000).] [This message has been edited by Barbara Dyer-Bennet (edited September 16, 2000).] [This message has been edited by Barbara Dyer-Bennet (edited September 16, 2000).] [This message has been edited by Barbara Dyer-Bennet (edited September 16, 2000).]
|
 |
Ramesh Donnipadu
Ranch Hand
Joined: Sep 16, 2000
Posts: 100
|
|
No. It doesn't print d. Because. method wrench() throws a NullPointerException which is not caught by any of the following catch blocks. So, after executing finally block, we still have a uncaught exception. In such cases, the method execution is terminated. Program control is passed back to line #5 after printing "c". ------------------
|
 |
Barbara Dyer-Bennet
Greenhorn
Joined: Sep 14, 2000
Posts: 10
|
|
Oh, duh! Thanks... sometimes I just can't see it through my own eyes. That was a big help.
|
 |
 |
|
|
subject: Question From JQuest Mock Exam...
|
|
|