Thread: what is polymorphism?

  1. #1
    newuser
    Guest

    what is polymorphism?

    woh,i am a newbiez.Getting a hard time in polymorphism,are they anyone who provides a good example of it? at least some good explanation and example coding for it. i will be grateful.

  2. #2
    Code Monkey Davros's Avatar
    Join Date
    Jun 2002
    Posts
    812
    Polymorphism is the ability for different objects to share the same interface, but the implementation mean by different. I guess a good example would be a stream object, where one implementation represented a memory stream, while the other is a file stream.

    Here's a definition from Foldoc:

    A concept first identified by Christopher Strachey (1967) and developed by Hindley and Milner, allowing types such as list of anything. E.g. in {Haskell}:

    length :: [a] -> Int

    is a function which operates on a list of objects of any type, a (a is a type variable). This is known as parametric polymorphism. Polymorphic typing allows strong type checking as well as generic functions. {ML} in 1976 was the first language with polymorphic typing.

    Ad-hoc polymorphism (better described as {overloading}) is the ability to use the same syntax for objects of different types, e.g. "+" for addition of reals and integers or "-" for unary negation or diadic subtraction. Parametric polymorphism allows the same object code for a function to handle arguments of many types but overloading only reuses syntax and requires different code to handle different types.

    See also {generic type variable}.

    In {object-oriented programming}, the term is used to describe variables which may refer at run time to objects of different {class}es.
    OS: Windows XP
    Compilers: MinGW (Code::Blocks), BCB 5

    BigAngryDog.com

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polymorphism - "pointers" or "references"?
    By Petike in forum C++ Programming
    Replies: 10
    Last Post: 06-04-2009, 05:06 PM
  2. A C++ program examples showing Polymorphism, please help.
    By MarkSquall in forum C++ Programming
    Replies: 19
    Last Post: 06-06-2008, 04:41 AM
  3. Question on polymorphism
    By 6tr6tr in forum C++ Programming
    Replies: 3
    Last Post: 05-06-2008, 09:05 AM
  4. change sorting method using polymorphism
    By Forever82 in forum C++ Programming
    Replies: 2
    Last Post: 07-31-2003, 01:21 PM
  5. Polymorphism & Overloaded Operators :: C++
    By kuphryn in forum C++ Programming
    Replies: 2
    Last Post: 09-13-2002, 08:40 PM