Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Polymorphism

Posted on 2006-07-23
5
312 Views
Last Modified: 2010-03-31
I am confused with polymorphism .I like to clear my understanding of polymorphism.
0
Comment
Question by:gauravflame
5 Comments
 
LVL 16

Expert Comment

by:suprapto45
ID: 17165184
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

by:
puneetmehta1 earned 250 total points
ID: 17165192
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

by:marchent
ID: 17165696
0
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 17166128
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
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 17167853
Mindprod has a nice glossary of all Java/ OO terminologies/ concepts:

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Protect jar file - windows app 2 65
ejb entity bean example issue 2 16
Is there a simpler dropbox system? 10 34
java mysql insert application 14 26
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question