Since concatenation of two strings will make new string object in string constant pool so why following code evaluates to No.
public class Main {
    public static void main(String[] args) {
        String s = "abcd";
        String s1 = "ab";
        String s2 = "cd";
        s1 = s1+s2;
        if(s1==s)
            System.out.println("YES");
        else
            System.out.println("No");
            }
}
 
     
    