This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from 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 "Question from" Watch "Question from" New topic

Question from

geeta rai
Ranch Hand

Joined: Sep 18, 2003
Posts: 48
public void divide(int a, int b) {
try {
int c = a / b;
catch (Exception e) {
System.out.print("Exception ");
} finally {
a) Prints out: Finally
b) Prints out: Exception
c) Prints out: Exception Finally
d) No output
I thought the answer is (a) but it is (c), can someone pls explain?
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
Hi geeta, none of the answers are correct because the resulting output is unpredictable (it depends on the parameter of the 'divide' method).
For example:
If we call divide(10,10) the output will be finally
if we cal divide (10,0) the output will be Exception Finally
The finally statement is always executed disregarding if it triggers an exception or not.
The answer is: Non of the above
Hope this helps.

- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. <br />- What truth? <br />- That there is no spoon!!!
It is sorta covered in the JavaRanch Style Guide.
subject: Question from