In first case your method() takes Object and
String as parameter. Now btw these two the most specific is String version of the method. So if you invoke method(null) the most specific method will be chosen and method(String s) will be executed.
In second case you have method(String s) , method(StringBuffer s) now for the argument null both can be matched since null can be assigned to a reference of type string or to a reference of type StringBuffer and hence there is this ambiguity for method(null) , Even if you have
method(String s) {} and method(Integer i) {} and invoke method(null); still the code will not complie because now null can be assigned to method String and Integer and both are more specific versions.
However if you have method(String s){} and method(Object o){} and as you know null can be assigned to String or Object reference and since String version is more specific here when compared to Object version of method , the String version of method is invoked.
Hope this clears.