title: Method overloading and choosing the most specific type
body: <p>The sample code is :</p>
  
  <pre><code>    public class OverloadingTest {
  
         public static void test(Object obj){
             System.out.println("Object called");
         }
  
         public static void test(String obj){
             System.out.println("String called");
         }
  
         public static void main(String[] args){
             test(null);
             System.out.println("10%2==0 is "+(10%2==0));
             test((10%2==0)?null:new Object());
             test((10%2==0)?null:null);
     }
  </code></pre>
  
  <p>And the output is :</p>
  
  <blockquote>
    <p>String called<br>
    10%2==0 is true<br>
    Object called<br>
    String called<br></p>
  </blockquote>
  
  <p>The first call to <code>test(null)</code> invokes the method with <code>String</code> argument , which is understandable according to <code>The Java Language Specification</code> . </p>
  
  <p>1) Can anyone explain me on what basis <code>test()</code> is invoked in preceding calls ? </p>
  
  <p>2) Again when we put , say a <code>if</code> condition :</p>
  
  <pre><code>    if(10%2==0){
          test(null);
      }
      else
      {
          test(new Object());
      }
  </code></pre>
  
  <p>It always invokes the method with <code>String</code> argument .</p>
  
  <p>Will the compiler compute the expression <code>(10%2)</code> while compiling ? I want to know whether expressions are computed at compile time or run time . Thanks.</p>