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.
Note that the "most specific" method is chosen. That (essentially) means that the class that is most removed from the Object class. What happens if you have two classes that are equally specific?
You get this error:
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
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,
Replace the words "overloaded" with "overridden" and tell us if what you originally said is correct.
SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Joel McNary
Bartender
Joined: Aug 20, 2001
Posts: 1815
posted
0
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.
Abdulla Mamuwala
Ranch Hand
Joined: Jan 09, 2004
Posts: 225
posted
0
Catch your point guys, thanks, sorry for using the wrong terminology Sandeep.
Sandip Shinde
Greenhorn
Joined: Apr 28, 2005
Posts: 6
posted
0
Thanks for great reply from u all, Got the exact basis for overloded methods invocation(more specific one will be called .. clear enough)