Share on Google+Share on Google+

SCJP Module-6 Question-27

Ads
The program given below will check the understanding of finally block of Exception Handling in Java.

Given below the sample code :

 Float pi = new Float(3.14f);
if (pi > 3) {
System.out.print("value of pi is greater than 3");
}
else {
System.out.print("value of pi is less than 3 ");
}
finally {
System.out.println("Now you know pi's value");
}

What will be the output of the following code ?

1. Error in compilation

2. value of pi is greater than 3 Now you know pi's value

3. value of pi is less than 3  Now you know pi's value.

4. Now you know pi's value

Answer

(1)

Explanation

Error in compilation is due to the "finally" clause without "try".

 

Advertisements

Posted on: July 15, 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.

Ads

Advertisement