SCJP Module-6 Question-27


 

SCJP Module-6 Question-27

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

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".

 

Ads