What is polymorphism? Explain with an example?  

"Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object. Example: function overloading, function overriding, virtual functions. Another example can be a plus ‘+’ sign, used for adding two integers or for using it to concatenate two strings.  

Showing Answers 1 - 17 of 17 Answers

Zaid

  • Mar 27th, 2005
 

An example would be: 
A "vehicle" class can be a part of a inheritance heirachy where derived classes are "sedan" and "SUV". Derived from "sedan" could be "Corolla", and derived from "SUV" could be "Pathfinder". 
 
CAR 
/  
SUV SEDAN 
/  
PATHFINDER COROLLA 
 
 
Now, using such an example, it is true that any object below in a heirarchy is also something that is directly up in the heirarchy. Hence, Pathfinder "is a" SUV, and SUV "is a" CAR. Also, Pathfinder "is a" CAR. 
Hence, using pointers of Base classes (higher in an inheritance heirarchy) can be assigned to objects of derived classes and can be used in a unified manner with the use of virtual functions. Hence, Polymorphism. 
 
(The plus "+" operator example used above would not be correct, as that is actually an overloaded operator (in the case the last poster presumed) and not precisely polymorphism).

sanneboyina

  • Feb 16th, 2006
 

A

  Was this answer useful?  Yes

Polymorphism is "acquiring many forms". as it has been stated that c++ has the property of polymorphism.Like as someone said the eg of vehicle...it can be said that the particular operation can acquire one or many forms

  Was this answer useful?  Yes

vsridevi

  • Sep 16th, 2008
 

C++ enables polymorphism - The ability of obejcts of different classes related by inheritance respond differntly to the same function call.

  Was this answer useful?  Yes

MCBod

  • Mar 31st, 2010
 

Polymorphism is a standard OO principle whereby one or more "sibling" classes may be defined as being children of some parent class, and where these classes provide some different implementations for the same method(s)
The Polymorphic concept is related to the late binding whereby a reference can be made to an instance of any one of these children, in the form of a reference to the parent class. Only at runtime does the system identify which instance of the method should be executed based on the actual class type being referenced

  Was this answer useful?  Yes

puzzlu

  • Sep 27th, 2010
 

The primary usage of polymorphism is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run-time (this is called late binding or dynamic binding).

Polymorphism is not the same as method overloading or method overriding. Polymorphism is only concerned with the application of specific implementations to an interface  or a more generic base class. Method overloading refers to methods that have the same name but different signatures inside the same class. Method overriding is where a subclass replaces the implementation of one or more of its parent's methods. Neither method overloading nor method overriding are by themselves implementations of polymorphism.

  Was this answer useful?  Yes

puzzlu

  • Sep 27th, 2010
 

In object-oriented programming, polymorphism is a generic term that means 'many shapes'. (from the Greek meaning "having multiple forms"). Polymorphism is briefly described as "one interface, many implementations."
Polymorphism is a characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form.

There are two types of polymorphism one is compile time polymorphism and the other is run time polymorphism. Compile time polymorphism is functions and operators overloading. Runtime time polymorphism is done using inheritance and virtual functions. Here are some ways how we implement polymorphism in Object Oriented programming languages.

Compile time polymorphism -> Operator Overloading, Function Overloading
Run time polymorphism -> Interface and abstract methods, Virtual member functions.

ilyas raja

  • Nov 30th, 2014
 

Explain the nature of lead pigment?

  Was this answer useful?  Yes

sugaa

  • Feb 12th, 2015
 

behaves differently in different instance is called polymorphism

  Was this answer useful?  Yes

Eric Nantel

  • Apr 23rd, 2015
 

Imagine with inheritance that you have a dog and a cat , both inheriting from animal . They both eat , but with only inheritance they eat the same thing . Is it the case ? Use polymorphism to change their kind of food .
Base class : Animal
Derived classes : Dog and Cat
Behavior : Eat (method)
Kind of behavior : Different (polymorphism)

  Was this answer useful?  Yes

heer

  • Jun 25th, 2015
 

Group of Classes

  Was this answer useful?  Yes

Hamza

  • Jan 6th, 2016
 

In programming language, polymorphism means that some codes or objects behave differently in different context.

  Was this answer useful?  Yes

Hamza132

  • Jan 6th, 2016
 

The word polymorphism means having many forms. Typically, polymorphism occurs when there is a hierarchy of classes and they are related by inheritance.
C++ polymorphism means that a call to a member function will cause a different function to be executed depending on the type of object that invokes the function.

  Was this answer useful?  Yes

malik rizwan raza

  • Feb 11th, 2016
 

Polymorphism is a technique in which we can use same function used in various classes depending on the object of the class.

  Was this answer useful?  Yes

Haseena

  • Jan 30th, 2017
 

Process of. Representing one form in many forms

  Was this answer useful?  Yes

sunil

  • Feb 26th, 2017
 

Several forms having same name is called polymorphism.
We have two types of polymorphism in C++.
1) Compile time Polymorphism or function overloading
2) Runtime Polymorphism or function overriding

  Was this answer useful?  Yes

Tech4 u

  • Jul 22nd, 2017
 

The ability to define more than one function with the same name is called polymorphism.
This provides the facility of sending the same message to objects of parent class and objects of the sub classes.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions