This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Darcy DeClute's Scrum Master Certification Guide: The Definitive Resource for Passing the CSM and PSM Exams and have Darcy DeClute on-line!
See this thread for details.
  • 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

How many types of polymorphisms ?

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

One person asked me in how many ways we are implementing polymorphism in Java?

I know only through overriding we are achieving polymorphism.
I think overloading is not kind of polymorphism (right or wrong )

Psl let me know if you are aware of any other ways of achieving polymorphism.

Thanks.
 
Marshal
Posts: 78681
374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you say, overriding.
Overloading isn't polymorphism becase the overloaded methods are in the same class as each other.
You will doubtless have heard the Design Patterns chaps' mantra

Favour composition over inheritance.


You can use something like this:-
Engine<-----------------Car
^
DieselEngine OttoEngine WankelEngine

As you know, Diesel Otto and Wankel were three German chaps who invented the engines which bear their name, Otto being the 4-stroke petrol (gas) engine and Wankel the rotary petrol (gas) engine. Now you can have different behaviours for each type of engine.

Now, you can have such silly code for any different kind of engine, in which case you are using polymorphism at the Car level, but it is actually polymorphism at the Engine level.
You can have the same for class MotorBicycle; motor cycles use Otto engines, or two-stroke engines. I am not sure whether you actually call it polymorphism in these circumstance.

CR

I tried editing the original post and bits went missing, so I have tried to reconstruct what I meant to say originally.
[ June 02, 2006: Message edited by: Campbell Ritchie ]
 
author and iconoclast
Posts: 24206
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some people -- and I am definitely not one of them -- like to call method overloading "static polymorphism" or "compile-time polymorphism", and overriding "dynamic polymorphism" or "runtime polymorphism". So a person asking you "how many kinds are there?" either wants to hear two or one.

Personally I dislike the idea, and prefer to think of polymorphism as referring only to runtime polymorphism.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are there other words for untyped languages?

I used to enjoy "polymorphism by coincidence" in VB4. There was no inheritance but you could try to call a method on any object. If it worked, hey, polymorphism! If not you handle the error and go on your way. So throw that in your answer and see what they say.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24206
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
Are there other words for untyped languages?

I used to enjoy "polymorphism by coincidence" in VB4.



The Rubyites call this "duck typing" -- if it walks like a duck, and quacks like a duck, then it's a duck.
 
I am not young enough to know everything. - Oscar Wilde This tiny ad thinks it knows more than Oscar:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic