Question: Can some one please explain in more detail. 

```
public class Car 
{
    public void disp(Object o)
    {
       System.out.println("Object called :");
    }
    public void disp(String s)
    {
       System.out.println("String called :"+s);
    }
}

```

Calling the main method as below

```
 public class CarMain {

public static void main(String[] args) {
    // TODO Auto-generated method stub
    Car car=new Car();
    car.disp(null); 
}

```

}

Output : String Called : null 

2nd scenario if I will pass Integer instead of Object in disp(Object o) then i am getting error as "The method disp(Integer) is ambiguous for the type Car"

As per understanding Java wrapper plays the major role here, but need well explanations.

Please help.

Answer: 
Let us take both the cases one by one:

> 
> **Case 1:** When we have two disp `overloaded` function, one with parameter `Object` and other with parameter `String`:
> 
> 
> 

```
public void disp(String s) { System.out.println("String called :"+s); }

public void disp(Object o) { System.out.println("Object called :"); }

```

In this case, it will refer to the most specific method. According to [Java Docs JLS 15.12.2.5](https://docs.oracle.com/javase/specs/jls/se7/html/jls-15.html#jls-15.12.2.5): 

> 
> A method m1 is strictly more specific than another method m2 if and
>  only if m1 is more specific than m2 and m2 is not more specific than
>  m1.
> 
> 
> 

So, in above case, the function accepting `String` is more specific then the one accepting `Object`, however, the opposite is not true.

Hence, in this case, when `null` is passed, it will go to the method with parameter String. But if you will pass `(Object)null`, it will go to the method with parameter Object.

```
car.disp(null); --> String called :null
car.disp((Object)null); --> Object called :

```

> 
> **Case 2:** When we have two disp `overloaded` function, one with parameter `String` and one with parameter `Integer`.
> 
> 
> 

```
 public void disp(String s) { System.out.println("String called :"+s); }
 public void disp(Integer i) { System.out.println("Integer called :"+ i); }

```

In this case, as none of the method is more specific then the other and both the function can accept null value, an appropriate function can not be decided in case of `null`. However, if you will pass `(Integer)null` or `(String)null`, no ambiguity will be there and appropriate function can be called.

```
car.disp(null); --> Compile time error (The method disp(String) is ambiguous for the type Car)
car.disp((Integer)null); --> Integer called :null
car.disp((String)null); --> String called :null

```
As the commenters have pointed out, you don't have a `disp(Integer..)` method, and if you do provide that, the method call works fine with `disp(12)`. 

As for the question of `disp(null)`, according to the Java language spec:

> 
> Overloaded methods and constructors are resolved at compile time by
>  picking the most specific method or constructor from those which are
>  applicable.
> 
> 
> 

Basically `String` is more specific than `Object`, so even though both apply to `null`, the String version of the method gets picked.