It will be treated as string reference. Which method to choose is very well explained in jls, Specific method
it says that:
Let m be a name and suppose that there are two declarations of methods named m, each having n parameters. Suppose that one declaration appears within a class or interface T and that the types of the parameters are T1, . . . , Tn; suppose moreover that the other declaration appears within a class or interface U and that the types of the parameters are U1, . . . , Un. Then the method m declared in T is more specific than the method m declared in U if and only if both of the following are true:
T can be converted to U by method invocation conversion. Tj can be converted to Uj by method invocation conversion, for all j from 1 to n. A method is said to be maximally specific for a method invocation if it is applicable and accessible and there is no other applicable and accessible method that is more specific.
Well, in simple terms, if suppose the constructor "public PowerSupply(Object voltage)" is getting called, u cannot convert Object to String. But if u call String constructor u can convert String to Object as Object is a super class, so ur String constructor is maximally specific. Try this example:
U will get a compiler error because even char can be converted to Object because Object is a super class of char, and also String can be converted to Object. So there are two maximally specific methods which is by itself not possible, there has to be only one, so a compiler error is displayed saying ambiguity in method call.
Joined: Mar 01, 2005
hi i am sorry i donno why the null is considered as string but i work out the code like shown below