ICSE Class 10 Computer Applications
Question 12 of 16
Using Library Classes — Question 14
Back to all questions 14
Question Question 14
Predict the output :
Integer c = 155;
Integer d = 155;
System.out.println(c == d);
System.out.println(c.equals(d));Output
false
true
Explanation
c == d compares two Integer objects and returns false because when we compare two objects using the operator "==", Java compares their reference i.e., their memory address and not their value. Since these are two different objects stored at two different locations in memory, Java produces result false
c.equals(d) method compares the values of the Integer objects after they are auto-unboxed by the compiler and converted to primitive data types. The function returns true as both the primitive type values are equal.