This week's giveaway is in the Spring forum.
We're giving away four copies of Microservices Testing (Live Project) and have Chris Love & Andres Sacco on-line!
See this thread for details.
Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
  • 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic