Halley's Blog

SJCP Question #02

Posted in Sun Certification by Halley on September 30, 2008

Given

//some code here
  try
 		{
 			//some code here
 		}
 		catch(SomeException se)
 		{
 			//some code here
 		}
 		finally
 		{
 			//some code here
 		}

Under which circumstances will the code on line 42 be executed?

A. The instance gets garbage collected.

B. The code on line 34 throws an exception.

C. The code on line 38 throws an exception.

D. The code on line 31 throws an exception.

E. The code on line 34 executes successfully.

Ans: BCE

Explanation: No matter what all happens in the try and the catch block, the statements in the finally block gets executed. And if an exception is thrown before the try block, control won’t even reach till the try block.

Advertisements