• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

polymorphism

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is polymorphism with examples now?
 
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
/Mike
 
Ranch Hand
Posts: 1246
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Go campfire!! great story on polymorphism.
check it out
http://www.javaranch.com/campfire/StoryPoly.jsp
reply
    Bookmark Topic Watch Topic
  • New Topic