Win a copy of Spark in Action this week in the Open Source Projects forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Question From JQuest Mock Exam...

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Oh, duh!
Thanks... sometimes I just can't see it through my own eyes. That was a big help.
 
No, tomorrow we rule the world! With this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic