Share on Google+Share on Google+

SCJP Module-6 Question-16

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.




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


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.


Advertisement null