• Post Reply Bookmark Topic Watch Topic
  • New Topic

polymorphism  RSS feed

 
sonali rao
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
What is single polymorphism and multiple polymorphism?
Can somebody explain? Thanks in advance.
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you got me on that one. I'm not sure I've ever heard that terminology before. Maybe it has to do with how a particular method is chosen at runtime based on the specificity of the methods available. For example, if you have something like:

Since a String is an Object, a Comparable and a String, which method is chosen. The answer is the most specific, which in this case is String. Note that by casting to the other reference types we can manage to call the other methods.
 
raimondas zemaitis
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Multiple polymorphism is a powerful feature, unfortunately not available with standard Java, consider example

if multiple polymorphism would be available, depending on Currency type appropriate method would be invoked, although IBankAccount has only one method declared. With current Java only deposit(Currency curr) is invoked always.
You can look into http://www.cyberdyne-object-sys.com/oofaq2/DynamicDispatch.htm (the above example is taken from their site), I once needed quite badly to have this functionality and stumbled onto this site. They say they've done Java implementation with this feature.
I think Sun could consider this as a future feature.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!