How many objects are going to be created as a result of the following operation?
"a"+"b"
Explanation
As a matter of fact, all String literals are generating String objects. So, the intuitive answer would be 3 (the 2 String literals "a" and "b" plus the result of their concatenation). However, since the literals in the example are constants whose value is instantly exposed to the compiler - the Java optimizer performs the concatenation in advance, thus creating only one object.

Следи за CodeGalaxy

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

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