What will be the result of compilation and execution of the following code?

Integer i = new Integer("10");
if (i.toString() == i.toString())
   System.out.println("Equal");
else
   System.out.println("Not Equal");
Explanation
Method toString() returns a String representation of an object.
Every time it is called on an object of class Integer, a new String object is created. Operator == compares two references to two String objects, and not the real values of those String objects.

Следи за CodeGalaxy

Мобильное приложение Beta

Get it on Google Play
Обратная Связь
Продолжайте изучать
тесты по Java
Cosmo
Зарегистрируйся сейчас
или Подпишись на будущие тесты