• 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: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone. I need some help to understand polymorphism. I read "How my Dog learned Polymorphism" but it looks like a litle complicated for me... maybe not suficient explanations... I need to know the basic, what it polymorphism is. If someone know about a text on the web, or if someone can explain something here to me, i'll be very happy!
Thanks a lot! Have a good day!
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I think the following link can help youThe Essence of OOP Using Java, Polymorphism and Interfaces, Part 1
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'll give this a shot.

Polymorphism is about software reuse. It comes in the form or overloaded and overidden methods.

Overriden method is a method that a subclass inherits from a superclass with the following qualities:
- The subclass's method arg list must be the same
- return type must be the same
- access level (ie private public etc) must not be more restrictive than that of the parent class's method.
.
// The benefit of using overriden method is that I get to define a behavior that's more specific according to subclass type. Note that we also get to use methods belonging to Human without having to redeclare them in Jeff class. This will not be possible if I had Jeff as a class on its own without a superclass Human. ie Software reuse.

That is only 1 aspect of polymorphism. The other is overloading. Let me know if this helped. If yes, I'll tell more about overloading later. Or you can read the Bates and Sierra book, which gives a good explanation.
[ June 17, 2005: Message edited by: Jeff Tian ]
 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try reading this thread
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Polymorphism?

The ability to associate many meanings to one method by means of the late binding mechanism.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marcio
See now if you have anything such as a car that already exists .....and if you would like to make any small changes in it then would you go again reinventing the wheel or would you just make changes to the existing system(car).Polymorphism is just for this basic purpose ..It is reusingwhat already exists ..For example you write a code for a building plan to build a Room which would have parameters as length ,breadth ,height and functions as guestsenter() ,guestleave(),removeshoes().and so on then having a bed room is no different then just changing the values of the three parameters and just changing the removeshoes() function. Thus it helps a lott to reuse what we already have...Basically poly means many and morphism means forms....that is having many forms of the same thing ....Polymorphism can be acheived by different implementations as having inheritence ,implementing interfaces ,overriding functions ......So basically it is for a single interface you can have many services.
njoi learning !!!
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Polymorphism is consitituted with two words, Poly and Morph. Poly means multiple and Morph means Shape. So if same method of an object can be used at multiple level depending upon the situation faced(parameter passed) at run time. Let me explain you with a simple example, Suppose a method named as move(). This method will react differently on different object. For example, for Fish its ation will be swim, for Bird its action will be fly, for Dog its action will be run.... now for a particular object depending on parameter passed the further reaction will take place... Suppose if you pass "Bread" parameter to move() method of Dog, obviously it will move toward Bread... and if you pass "Stick" parameter to move() method of Dog, it will run away... Similary way in Java, same method will be used at different situation depending on parameter passed and over object called.
I hope this will further clarify the doubts.
 
The first person to drink cow's milk. That started off as a dare from this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic