• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Polymorphism

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


Polymorphism means many forms and in java Overloadig is best example of polymorphism.Can anyboday explanin me how it can implement in java?
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks...but i want some example of code....so taht i can understand esaily.....
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This may help: http://www.javaranch.com/campfire/StoryPoly.jsp
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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...
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
lowercase baba
Posts: 12754
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!