Home Tutorial Java Scjp Part6 SCJP Module-6 Question-9

 
 

SCJP Module-6 Question-9
Posted on: July 14, 2010 at 12:00 AM
The given sample program will test your understanding about the use of try, catch, finally in Java. This helps very much to clear your concepts about the exception handling.

Given below the sample code :

public class SuperClass {
static String str = "";
public static void main(String[] args) {
try {
str += "2";
throw new Exception();
} catch (Exception e) { str += "3";
} finally { str += "4"; interrupt(); str += "6";
}
System.out.println(str);
}
static void interrupt() { int a = 0; int b = 8/a; }
}

What is the output of the above code:

1.  2  3  4

2.  2  3  4

3.  2  3  4  6

4.  Error in compilation.

Answer :

(4)

Explanation :

Compile error is due to the ' / by zero ' operation of method "interrupt()".

Related Tags for SCJP Module-6 Question-9: