I need clarification about overloading/overriding, polymorphism, dynamic data binding. 1. Can we achieve polymorphism by overloading or by overriding or by both? 2. Please explain the above with respect to the dynamic data binding? [ January 23, 2007: Message edited by: Srinivasa Datla ]
OOPS Peter! I didn't think about my question to be answered by a school boy who always bothers about homework. . I am always confusing about overloading and overriding which are related to polymorphism and data binding. Please clarify this.
Overloading is a process of defining a method that has same name and different argument list as another method in the same class whereas over-riding is a process of defining a method having same name and argument list as another method in its parent class.
Now it should be clear to you which one acheives polymorphism. [ January 23, 2007: Message edited by: rao raghu ]
RAGHU<br /> <br />"When the going gets tough, the tough get going"
In a simple sense, overriding occurs between different classes in a hierarchy. So, a subclass overrides a method inherited from a parent or an ancestor. So, overriding always involves a hierarchy of some sort.
It is through a hierarchy chain, and different behaviors of classes on a common heirarchy chain, that polymorphism is all about. Classes on a hierarchy share behavior, although, by overriding, child classes can implement that common behavior in a customized way - that's what polymorphism is all about.
Overloading can be thought of as potentially happening in a single class, with no hierarchy involved. I can define one class with a million methods named bombsAway(), so long as each method has a different method signature. There's absolutely no obligation for any of those methods to do the same thing. They're just using similar names. In that case, polymorphism doesn't even have any meaning.
Overriding - always happens between classes in a heirarchy chain.
Overloading - can occur within a single class, and does not need to involve a class hierarchy.