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

 
 

Share on Google+Share on Google+
SCJP Module-6 Question-9
Posted on: July 14, 2010 at 12:00 AM
Advertisement
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()".

Advertisement

Related Tags for SCJP Module-6 Question-9:


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.

Posted on: July 14, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com