• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Question From JQuest Mock Exam...

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<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).]
 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh, duh!
Thanks... sometimes I just can't see it through my own eyes. That was a big help.
 
Beauty is in the eye of the tiny ad.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic