Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

clarify overloading/overriding, polymorphism, dynamic data binding  RSS feed

 
Srinivasa Datla
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How about you tell us what you think the answer might be? Then we won't think you're just someone trying to get us to do your homework.
 
Srinivasa Datla
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

-Sri
[ January 23, 2007: Message edited by: Srinivasa Datla ]
 
Rao Raghu
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

-Cameron McKenzie
 
Srinivasa Datla
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Cameron. I got it.

- Sri
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!