Originally posted by Kuldeep Yadav: Hi Ranchers, One of the query about overloading in my mind. As we know we can overload methods. In that method having same name but different parameters OK. e.g
But we can do by taking different name of method.
So what is acual purpose of overloading ?
Kuldeep the point is that how many methos names you will use to denote the functionality. For the simplest example take we have a method named add(int i, int s)
and this methos is overloaded for float and LONG. So now if we go to your way we have to name functions like addFloat or addLong BUT as seen that it is really simple and apt to use one name add() for all the datataypes and arguments. [ October 15, 2008: Message edited by: Himanshu Gupta ]
Himanshu Gupta is right. And there is an example you can find quite easily; you can get the String contents of a message if you know its messageName, or if you know its messageId. You can pass the name or the ID and get the message returned in both cases.
Probably best to restrict overloading of methods to instances where all the methods do something similar, but with different kinds of parameter.