How many objects are going to be created as a result of the following operation?
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.
Java Quiz
Start Quiz

or Read more about Java Quiz

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback