Solved

# Polymorphism

Posted on 2006-07-23
308 Views
I am confused with polymorphism .I like to clear my understanding of polymorphism.
0
Question by:gauravflame

LVL 16

Expert Comment

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
0

Accepted Solution

puneetmehta1 earned 250 total points
Polymorphism means the ability of a single variable of a given type to be used to reference objects of
different types and to automatically call the method that is specific to the type of object the variable references.
This enables a single method call to behave differently, depending on the type of the object to
which the call applies.
0

LVL 13

Expert Comment

0

LVL 8

Expert Comment

Polymorphism means 'single thing in many forms'

For an object oriented language following are types of polymorphism

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.

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
0

LVL 30

Expert Comment

Mindprod has a nice glossary of all Java/ OO terminologies/ concepts:

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

## Featured Post

### Suggested Solutions

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.