Though late, may be useful for someone still come across this:
String first = "abc";
//One instance object in pool created. Instance variable “first” refers/points to pooled object
String second = new String("abc");
//One instance object in heap created. Object in pool creation step will be skipped on account of first statement.
So in total 2 instance objects will be created. One in pool and other in heap
Detailed Explanation
String first = "abc";
Here a string object with content "abc" created in pool. The instance variable “first” will point to pool object with content “abc”.
String second = new String("abc");
Here another string object with content "abc" will be created in heap. The instance variable “second” will point to heap object with content “abc”. A string object with content "abc" creation in pool will be skipped on account of 1st statement. Reason below.
Reasons
If assumed prior statement (String first = "abc";) is not there with same content, then generally with “new” keyword, 2 string objects will be created one in heap (outside pool) and the other in pool(a subset area of heap).
Also the instance variable "second" should point to heap object only, irrespective of whether the objects is in pool or not.
Now on account of the presence of prior statement (String first = "abc";) with same content as in new String("abc"), only one object (with content "abc") is retained in pool.
So on account of 1st statement, the second statement will have only 1 object created instead of 2 and that object is in heap. Pool object creation will be skipped.
//Additional Test on the concept
System.out.println(first==second); //returns false. Because first points to pool object while second points to heap object. And both objects are different (on account of different memory locations).
second = second.intern(); //After interning, second now points to pool object. Note: intern is used so that reference variable points to pool area object and not heap object. Clearly it is applicable when we use new keyword.
System.out.println(first==second); //returns true. Because now both first and second objects now points to same pool object.