File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "polymorphism" Watch "polymorphism" New topic



Joined: Nov 26, 2001
Posts: 5
what is polymorphism with examples now?
Mikael Jonasson
Ranch Hand

Joined: May 16, 2001
Posts: 158
This is really a post for the beginner-forums, but sure I'll give you a few examples.
Polymorphism is "the art of changing", that is where sub-classes performs differently then their parents. The classical examples is how animals move differently:

You then create instances of dog and fish in the code above, but reference them using animal:

Then when you call your Move()-method in the different objects, Java keeps track of which instance it is and do what's needed.
Normal implementation for this is Print()-methods. Say you have a list of different items, all you need to do is call print in each to print it. Java and poylmorphism will keep of what to print, and how.
Did that help?
Fei Ng
Ranch Hand

Joined: Aug 26, 2000
Posts: 1242
Go campfire!! great story on polymorphism.
check it out
I agree. Here's the link:
subject: polymorphism
It's not a secret anymore!