ICSE Class 10 Computer Applications
Question 7 of 16
Using Library Classes — Question 9
Back to all questions 9
Question Question 9
Predict the output.
int res = Integer.valueOf("100").compareTo(new Integer(100));
System.out.println(res);Output
0
Explanation
Here, Integer.valueOf("100") returns an Integer object storing 100 and new Integer(100) creates a new Integer object with the value 100.
Integer.compareTo() compares two Integer objects numerically, after auto-unboxing is performed by the compiler and the Integer objects are converted to integer type values. The function compareTo() returns 0 as primitive values of both the objects are equal.