wood burning stoves 2.0*
The moose likes Beginning Java 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 » Beginning Java
Bookmark "Polymorphism" Watch "Polymorphism" New topic
Author

Polymorphism

M�rcio Soeiro
Greenhorn

Joined: Jun 16, 2005
Posts: 1
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!
pradeep jaladi
Ranch Hand

Joined: Nov 21, 2004
Posts: 65
Hi,

I think the following link can help youThe Essence of OOP Using Java, Polymorphism and Interfaces, Part 1


Pradeep.Jaladi
Jeff Tian
Greenhorn

Joined: Jan 06, 2005
Posts: 12
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 ]

The magic of believing in yourself is to risk all that you have for a dream <br />that nobody sees but you. (Million Dollar Baby)<br /> <br />SCJP 1.4
miguel lisboa
Ranch Hand

Joined: Feb 08, 2004
Posts: 1281
try reading this thread


java amateur
Pete Low
Greenhorn

Joined: May 25, 2005
Posts: 10
Polymorphism?

The ability to associate many meanings to one method by means of the late binding mechanism.
Archies Gomes
Ranch Hand

Joined: Jun 19, 2005
Posts: 34
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 !!!
Abrahim Daver
Ranch Hand

Joined: Aug 06, 2004
Posts: 69
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.
 
Don't get me started about those stupid light bulbs.
 
subject: Polymorphism