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

 
 

SCJP Module-6 Question-27
Posted on: July 15, 2010 at 12:00 AM
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".

 

Related Tags for SCJP Module-6 Question-27:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.