aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes try, catch question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "try, catch question" Watch "try, catch question" New topic
Author

try, catch question

Jay Ashar
Ranch Hand

Joined: Oct 13, 2002
Posts: 208


A 0
B 1
C 2
D 3
E 4

what will be the output of this code... this mock exam answer says ADE
[ Jess added UBB [code] tags to preserve whitespace. Check 'em out! ]
[ October 31, 2002: Message edited by: Jessica Sant ]

SCJP 1.4<br />SCWCD 1.3
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

Did you try running it??
The output of the program is 034, just like the mock exam answer.
during the first iteration of the code 'i' goes up to 2, 'j' goes down to 0
i/j ( -> 2/0) produces an ArithmeticException: Divide By Zero
which is caught by the catch (ArithmeticException e) and prints '0'
the finally is always executed and prints '3'
then the code exits the try/catch and prints '4'


- Jess
Blog:KnitClimbJava | Twitter: jsant | Ravelry: wingedsheep
Ron Newman
Ranch Hand

Joined: Jun 06, 2002
Posts: 1056
Did you try compiling and running it? That's the best way to understand the answers to questions like this.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: try, catch question