aspose file tools*
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

Nidhi Jain
Ranch Hand

Joined: Mar 26, 2006
Posts: 31
Hi,


Polymorphism means many forms and in java Overloadig is best example of polymorphism.Can anyboday explanin me how it can implement in java?
Veeresh Hosur
Ranch Hand

Joined: Dec 18, 2007
Posts: 32
There are different types of polymorphism in java

1)Method Overloading
2)Method overriding at inheritance
3)Method overriding by implementing interface.

1)Method Overloading:
This is the concept where the method name will be same where as the parameters that's been passed to the method will be different. In this scenario there is no concern with the return type

2)Method Overriding at inheritance:
This is the concepth where the method signature including the return type will be same in the child classes.

3)Method overrding by implementing interface
This is the concepth where the methods of the interface will be implement here also the method signature will be same in the implementing classes.

Thanks
Veeresh
Nidhi Jain
Ranch Hand

Joined: Mar 26, 2006
Posts: 31
Thanks...but i want some example of code....so taht i can understand esaily.....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
This may help: http://www.javaranch.com/campfire/StoryPoly.jsp


Ping & DNS - my free Android networking tools app
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Originally posted by Veeresh Hosur:
There are different types of polymorphism in java

1)Method Overloading


Explain to me how method overloading is a type of polymorphism...


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
The software term polymorphism is commonly defined as having several methods (functions) that have the same name but have different behavior.

Below is an overloaded constructor method as an example.

public Account(String s, ID i, boolean b) {..create an account this way..}

public Account(Properties p) {..create an account another way..}



Below is an overloaded method named processAccount as an example.

public void processAccount(String s, ID i, boolean b) {..process an account this way..}

public int processAccount(Properties p ) {..process an account another way..}


Both examples illustrate polymorphic behavior.
[ April 17, 2008: Message edited by: James Clark ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11422
    
  16

Originally posted by James Clark:
The software term polymorphism is commonly defined as having several methods (functions) that have the same name but have different behavior.


really? do you have a reference for that? what you are describing sounds like overloading, not Polymorphism


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
It sounds like 'overloading' because that is what it is. And this is an implementation of polymorphic behavior. They are not different concepts. They are related.

There are other types of polymorphic behavior, 'overloading' is only one type.

Reference:
Dr. F. Grossman and Dr. N. Surrendra from the School of Computer Science and Information Systems
[ April 17, 2008: Message edited by: James Clark ]
Hari Srinivas
Ranch Hand

Joined: Mar 26, 2008
Posts: 46
Well Fred,James probably didn't get the definition completely right...but I don't see any reason why overloading isn't a type of polymorphism... And Fred I thought the link that you gave was for Type Polymorphism... May be this one would be of more help Polymorphism
 
jQuery in Action, 2nd edition
 
subject: Polymorphism