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
Зареєструйся Зараз
або Підпишись на майбутні тести