title: Passing null to the method preferring String, not Object
body: <p>I am facing an issue in my program and I made it clear with a small code snippet below.  Can anyone explain why this is happening?</p>
  
  <pre><code>class ObjectnullTest {
  
      public void printToOut(String string) {
  
          System.out.println("I am null string");
      }
  
  
      public void printToOut(Object object)
  
          System.out.println("I am  null object");
      }
  
  
  
  class Test {
  
      public static void main(String args[]) {
  
          ObjectnullTest a = new ObjectnullTest();
          a.printToOut(null);
  
      }
  }
  </code></pre>
  
  <p>This always prints <code>I am null string</code> .</p>
  
  <p>I want to know the reason so that I can modify the code .</p>