SCJP Module-6 Question-8


 

SCJP Module-6 Question-8

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

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)

 

Ads