Understanding which constructor is chosen and why
<p>Why following program every time prints <code>I'm string</code> and not <code>I'm object.</code> or <code>I'm int.</code>?</p>

<pre><code>public class Demo {

    public Demo(String s){
        System.out.println("I'm string");
    }

    public Demo(int i){
        System.out.println("I'm int.");
    }

    public Demo(Object o){
        System.out.println("I'm object.");
    }

    public static void main(String[] args) {
        new Demo(null);
    }
}
</code></pre>

<p>Also if I replace <code>int</code> with <code>Integer</code>. It gives error as <code>The constructor Demo(String) is ambiguous.</code> Why?</p>
