Link to home
Start Free TrialLog in
Avatar of gauravflame
gauravflame

asked on

Polymorphism

I am confused with polymorphism .I like to clear my understanding of polymorphism.
Avatar of suprapto45
suprapto45
Flag of Singapore image

Here is my understanding.

For example that you have a class called Animal and you also have other classes like Dog and Bird. All of them are able to walk() so Animal have the method of walk() but Bird and Dog are different in the way they are walking and each of them has its own behavior.

So in conclusion, polymorphism allows you to implement different behavior with the same name of methods.

David
ASKER CERTIFIED SOLUTION
Avatar of puneetmehta1
puneetmehta1

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kaliyugkaarjun
kaliyugkaarjun

Polymorphism means 'single thing in many forms'

For an object oriented language following are types of polymorphism
1) Function overloading
2) Operator overloading

Function overloading means u can use functions with same name in a program provided
i) either the functions must have different number of arguments or the order of arguments shud not be same. Remeber function overloading doesnot depend upon return type of functions.
e.g. Function double area(int radius) //for circle
int area(int length, int breadth) //for rectangle

int Rectangle_area= area(2,5); //function call
double circle_area = area(4);

Since the no of arguments is different compiler can easily call acurate function to calculate area.

2) Operator overloading.

Operator like +, - ,* , / normally operate on primitive data types like integer, float etc.
But we can make them operate on custom data types i.e user defined

(comples numbers for e.g...currently complex number is a data type in c++ though
)

U need to write function thst operates on custom data type with operator

The whole explaination was regarding c++

For java
http://www.javaworld.com/javaworld/javatips/jw-javatip30.html
Avatar of Mayank S
Mindprod has a nice glossary of all Java/ OO terminologies/ concepts:

http://mindprod.com/jgloss/polymorphism.html