String s1 = "A";
String s2 = "A"+"B";
Now in total you have 3 objects : "A" , "B" and "AB" And one more thing in addition "B" object is eligible for Garbage Collection ...
This is false.
You have 2 objects. One is an instance that has the value "A", the other is an instance that has the value "AB". "B" is not eligible for garbage collection because it is a String literal, not an object, and the same can be said for "A" and "AB".
The relevant part of the JLS is 15.28 where constant expression is defined.
"A" + "B" is a constant expression and is inlined at compile-time.