Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Please explain Polymorphism

polymorphism

  • Please log in to reply
3 replies to this topic

#1 Patrick

Patrick

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 101 posts

Posted 06 October 2007 - 10:53 PM

Can anyone please explain me what is Polymorphism giving any small example. I don't need any program as example , any simple idea from real world will also help or mention any helpbook if you have any idea of
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 08 October 2007 - 08:30 AM

A cat is an animal. A dog is an animal. A dog is not a cat and vice versa.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 08 October 2007 - 02:58 PM

To understand polymorphism, you need to understand a little bit about class inheritance and hierarchy.

      ANIMAL
     /       \
   DOG       CAT
    |        || |
Rottweiler   ||  \ Cheshire
             | \ Tabby
             \ Tiger

Hierarchy:
Anything defined in a level above the current level can be accessed by lower levels. A Rottweiler is a dog, but a dog isn't necessarily a Rottweiler.

Inheritance:
Cheshires, Tabbies, and Tigers are on the same level; they can each access the functions and fields specified by CAT, but each has its own functions and fields that other cats can't access. For example, tigers can't execute Cheshire.hugeSmile(), but both Cheshires and tigers can execute CAT.cleanSelf().

The polymorphism part:
Every animal has a saySomething() method, but it will do something different for each subclass of animal. Tabby.saySomething() will give "Meow", but Cheshire.saySomething() will give ":D".
  • 0

#4 Guest_NeedHelp_*

Guest_NeedHelp_*
  • Guest

Posted 09 October 2007 - 05:09 PM

Also check here: http://forum.codecal...ht=Polymorphism
  • 0





Also tagged with one or more of these keywords: polymorphism

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download