Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Why polymorphism exists in java  RSS feed

 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Plz tell me why polymorphism exists in java
**Is it only for overloading and overriding or anything else
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See Wikipedia: Polymorphism in object-oriented programming.
 
Raj Kumar Bindal
Ranch Hand
Posts: 418
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read the document from site.
But,this is what i was already expecting.
**Polymorphism exist only to implement overriding.
Thanx
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, polymorphism doesn't exist to implement overriding.

Overriding exists to implement polymorphism.

And that's a gross over simplification.

CR
 
Srinivas Kalvala
Ranch Hand
Posts: 257
Firefox Browser Hibernate Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raj Kumar Bindal:
Plz tell me why polymorphism exists in java
**Is it only for overloading and overriding or anything else


Hi Raj,

With out polymarphisam, I think there is no life for OO design. If you observe the Design Patterns, almost all patterns depends on the Run time ploymarphism only.

How a particular language achives that purely depends on the desingers of the languages.
For instance take the Java, it supports the ploymarphisam through interface implementations very well.

Hope you got the point.

Thank you.



 
Gem Cameron
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the JavaRanch article on "How my Dog learned polymorphism"?

This is very good and by understanding how polymorphism works you may start to see how useful it is in Java and why it is used...

Maybe you need to go right back to OO concepts and think about how OO is used to model real life systems...
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OO is used to model real life systems


Did you mean modeling the real world outside of software? Just a caution ... that will start fires in some communities. OO evolved from simulation of real world things, and it's fun and useful to model that way some times. OO pioneers even marketed the value of modeling real things and I still buy it as part of the appeal. But taking the real world literally runs into some tough problems. Be prepared to make the jump from real things into imaginary things and totally artificial software constructs fairly early in the modeling process.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!