> No string with “ab” is there in string pool, so JVM will create string “ab” in string pool and str will be a reference variable which will refer to it.

str.concat("cd")

> cdwill be concatenated with ab and new string “abcd” will be formed. No string with “abcd” is there in pool, so JVM will create string “abcd” in string pool, but there won’t be any reference variable to “abcd” (we are just using it only in syso statement), meanwhile str will still be pointing to “ab”.