If there is already a string literal “Cat” in the pool, then only one string “str” will be created in the pool. If there is no string literal “Cat” in the pool, then it will be first created in the pool and then in the heap space, so a total of 2 string objects will be created.
Why Java uses the concept of String literal? To make Java more memory efficient (because no new objects are created if it exists already in the string constant pool)