How to know which gets invoked ?? I tried it out the string version does but how ? and also if we remove the string version the Integer Version gets invoked and removing that then the Object Version so how do we know which to choose?
I complied your code and it throws the error like "reference to method is ambiguous, both method method(String s) and method(Integer s)".
The rule is something like this:
The method which is nearest to the parameter is called first, means, the child class object is first checked, then its parent, and then its parent and so on..
e.g
If we comment out the "integer version", then it looks for parent class e.g
You're welcome I saw this type of questions many time here. Just search this forum with tags like "method calling sequence", "which method get invoked". etc
Actually there is a important thing to remember. If you have overloaded methods with parameters in the same inheritance tree then the lowest level subclass will be invoked. If any other type is included then it will be ambiguous as both the types can accept the argument value.
[ SCJP 6.0 - 90% ] , JSP, Servlets and Learning EJB.
Try out the programs using a TextEditor. Textpad - Java 6 api