ICSE Class 10 Computer Applications Question 8 of 16

Using Library Classes — Question 10

Back to all questions
10
Question

Question 10

Find the error:

Integer obj = new Integer("A"); 
System.out.println(obj);
Answer

Integer obj = new Integer("A"); statement will generate NumberFormatException at the time of conversion of String argument "A" to Integer object. The exception is raised because "A" is not a valid string representation of a numeric value, therefore it cannot be converted to Integer object.