Here you have method painter() which you have overloaded in the same class Tester. Generally the term overloaded is used in case of inheritance, that is when we have a base class and a sub class, and than in the sub class we overlaod the method from the base class. Anyways,
Generally in the case of an overloaded method, the more specific of the two methods is selected. In your case the parameter which you are passing to your methods is "null".
Now, String is a subclass of Object, therefore "null" is more applicable to String rather than Object class.
Lets take another example to clarify it, lets replace "null" by a literal "8". Refer to the code below:
The output of this code will be Integer selected, although both the painter methods are applicable, the integer method is selected becuase it is more specific of the two.
The output of this code will be Integer selected, although both the painter methods are applicable, the integer method is selected becuase it is more specific of the two
Actually, it is because you are passing an integer. Specificality doesn't apply to primitives, as they do not extend one another. There's no confusion to the compiler because a literal 8 is always and forever an integer. To get a literal 8 as a long, you owuld have to use 8L.
Joined: Jan 09, 2004
Catch your point guys, thanks, sorry for using the wrong terminology Sandeep.
Joined: Apr 28, 2005
Thanks for great reply from u all, Got the exact basis for overloded methods invocation(more specific one will be called .. clear enough)