title: Java: String literal and + operator
body: <pre><code>import java.util.*;
  import java.lang.*;
  import java.io.*;    
  
  class Test {
     public static void main (String[] args)  {
  
        String a="hello"+"world";  //line 1
        String b="hello";
        String c="world";
        String d=b+c;
        String e="helloworld";
        System.out.println(e==a);
        System.out.println(a==d);
       }
  }
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>true
  
  false
  </code></pre>
  
  <p>From this discussion <a href="https://stackoverflow.com/questions/11408427/how-does-the-string-class-override-the-operator">How does the String class override the + operator?</a> I understood that 'a' and 'e' will refer to same String literal object. </p>
  
  <p>Could anybody please tell </p>
  
  <ol>
  <li><p>Why <em>a</em> and <em>d</em> are not referring to same string literal object?</p></li>
  <li><p>How many objects were creating in line 1</p></li>
  </ol>