It's not a secret anymore!
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
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. - What truth? - That there is no spoon!!!
I agree. Here's the link:
subject: Question from
It's not a secret anymore!