Integer i1 = 40; Integer i2 = new Integer(40); System.out.println(i1==i2);
时间: 2023-12-06 10:03:44 浏览: 176
False.
Explanation:
The == operator in Java checks if two objects have the same memory address, meaning they are the exact same object. In this case, i1 and i2 are both Integer objects with the same value (40), but they are not the same object in memory.
When you use the new keyword to create an Integer object (as in i2 = new Integer(40)), Java creates a new object in memory with its own unique memory address.
Therefore, i1 and i2 have different memory addresses and are not the same object, so the == operator returns false.
阅读全文