title: The connection between 'System.out.println()' and 'toString()' in Java
body: <p>What is the connection between <code>System.out.println()</code> and <code>toString()</code> in Java? e.g:</p>
  
  <pre><code>public class A {
      String x = "abc";
  
      public String toString() {
          return x;
      }
  }
  
  public class ADemo {
      public static void main(String[] args) {
          A obj = new A();
          System.out.println(obj);
      }
  }
  </code></pre>
  
  <p>If main class runs, it gives an output as <code>"abc"</code>. When I remove the code which overrides <code>toString()</code>, it gives an output as <code>"A@659e0bfd"</code>. So, can anyone explain what is the working principle of <code>System.out.println()</code> when I pass the <code>obj</code> object reference as an argument to it? Is it fully connected with <code>toString()</code> method?</p>