What will be the result of the following code execution:

String s1 = "abc";
String s2 = new String("abc");
String s3 = "abc";
System.out.println(s1 == s2);
System.out.println(s1 == s3);
System.out.println(s1 == "abc");
Explanation

String literals refer to the same instance of the String class. Therefore s1 == s3 and s1 == "abc" comparisons will result in true.

New instance of the class is created with the new operator, therefore s1 == s2 will result in false.


Следи за CodeGalaxy

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

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