Share on Google+Share on Google+

SCJP Module-6 Question-8

Advertisement
The program given below will test your knowledge of exception handling in Java and helps you for better understanding of Java programs.

Given below the sample code :

public class section68 {
public static void main(String[] args) {
for (int a= 0;a < 10; ++a) {
try {
if (a % 3 == 0)
throw new Exception("Exception1");
try {
if (a % 3 == 1)
throw new Exception("Exception2");
System.out.println(a);
} catch (Exception inside) {
a*= 2;
} finally {
++a;
}
} catch (Exception outside) {
a += 3;
} finally {
++a;
}
}
}
}

What is the output of the above code :

1. Compile error

2.. 0 1 2 3 .....10

3.  4  7

4.  5  8

Answer :

(4)

 

Advertisements

Posted on: July 14, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.