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

 
 

SCJP Module-6 Question-16
Posted on: July 14, 2010 at 12:00 AM
The Sample Java program given below will check you understanding about the Exception handling in Java and it also test how you will handle exceptions when it arises.

Given below the sample code :

public class A {
static void test() throws Error{
if (true) throw new AssertionError();
System.out.print("test ");
}
public static void main(String[] args) {
try { test(); }
catch (Exception ex) { System.out.print("exception "); }
System.out.print("end ");
}}

What will be the out put of the following code ?

1. test    exception   end

2. exception     end

3. test

4.Gives compile error.

Answer

(4)

Explanation

Above code will give uncaught exception as output. Since it is of type "error " so it should be handled by error class object.

Related Tags for SCJP Module-6 Question-16: