At compile time, the value of a is not available as all objects are created at runtime. But string literal “123” is marked for string pool at the compile time.

At runtime, all marked strings are added in the string pool, in our case it is “123” and value of a is already in the string pool due to previous statements in our example. The concatenation operation cant be done in string pool because it is just the storage area for string pool. So JVM fetches the value of a and string literal “123” from the pool and then concatenates it and the resultant value is stored in the heap memory.