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

 
 

SCJP Module-6 Question-11
Posted on: July 14, 2010 at 12:00 AM
The program given below will test your understating about the formating data from String to Float.

Given below the sample code :

1  public class Section611 {
2  public static void main(String[] args) {
3  convert("illlegal");
4  }
5  public static void convert(String s) {
6  try {
7  float f = Float.parseFloat(s);
8  } catch (NumberFormatException ne) {
9  f = 0;
10 } finally {
11 System.out.println(f);
12 }
13 }
14 }

Find the output after execution of the above code ?

1. 0.0

2. Compilation fails

3. illegal

4. It 'throws' number format exception.

Answer :

(2)

Explanation :

Compilation fails because the variable at line 9 doesn't have any type because the variable ' f ' at line 7 has it's scope within 'try' block.

 

 

Related Tags for SCJP Module-6 Question-11:


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.