Share on Google+Share on Google+

SCJP Module-6 Question-5

Advertisement
The program given below will test your understanding about the Exception handling and helps for the preparation of SCJP exams.

Given below the sample code :

1   import java.io.StreamCorruptedException;
2   import java.net.MalformedURLException;
3   public class SuperClass {
4   public static void main(String[] args) {
5   try {
6   throw new MalformedURLException("error in url");
7   throw new StreamCorruptedException("error in file");
8   throw new Exception("erorr");
9   System.out.println("try block ");
10  } catch (MalformedURLException e) {
11  System.out.println("error in URL");
12  } catch (StreamCorruptedException e) {
13  System.out.println("error in file contents");
14  } catch (Exception e) {
15  System.out.println("exception");
16  } finally {
17  System.out.println("in finally block");
18  }
19  System.out.println("success");
20  }}

How can we correct the above code :

1. No error in this code.

2. Remove line number 7,8 & 9.

3. Remove Catch block at line 12.

4  Remove line number 7,8 & 9. and Remove Catch block at line 12.

Answer :

(4)

Advertisements

Advertisement

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.