Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Polymorphism

  Asked By: Jaxson    Date: Aug 12    Category: Java    Views: 2718
  

I'm learning J2SE right now..
Could anyone of you explain what polymorphism is?

Share: 

 

24 Answers Found

 
Answer #1    Answered By: Estella Mitchell     Answered On: Aug 12

Polymorphism is the mean for you do different things, with same name.

 
Answer #2    Answered By: Felicia Hill     Answered On: Aug 12

Is it like making one method to do many actions??

 
Answer #3    Answered By: Corinne Rogers     Answered On: Aug 12

The definition at http://www.webopedia.com/TERM/p/polymorphism.html gives a bit
more information to support Mark's answer.

 
Answer #4    Answered By: Agatha Miller     Answered On: Aug 12

Here is another example of Polymorphism.

There are various database drivers. Each one implements the same
methods specified in the SUN Microsystems interfaces. The signature
(interface) is same, but the implementation is different.

 
Answer #5    Answered By: Sonya Flores     Answered On: Aug 12

That is plain wrong.
Java does not support polymorphism. So your example is wrong.
Java only supports single inheritance and NOT multiple inheritance.
In short words in Java one class can extend another one BUT only ONE class
(and not many which would be polymorphism)

 
Answer #6    Answered By: Eric Foster     Answered On: Aug 12

You need to go read up on it

http://www.itee.uq.edu.au/~comp2500/Eckel%20text/Chapter07.html

 
Answer #7    Answered By: Oliver Evans     Answered On: Aug 12

i don't agree with you
i think java is support in polymorphism. also multiple inheritance.

example.
single inheritance :
.... extends ....
multiple inheritance :
..... extends ..... implements .....

 
Answer #8    Answered By: Geb Chalthoum     Answered On: Aug 12

"Polymorphism" means "A method(call?) acts different
depending upon the nature(type) of the parameter which
is passed"

Generally polymorphism helps robust Type checking at
the compilation time & making the programmer's life
little bit easier (atleast we dont want learn
different different method names for each type it
accepts)

If you want more info just go through
"java.lang.String" class's javadoc info. there u can c
a method named "valueOf()" for each & every
type(int,float,double,boolean,char,etc.,)

thnks to Polymorphism so we dont want to remember a
unique name for each & every type toIntValueOf,
toFloatValueOf, toDoubleValueOf,
toBooleanValueOf,toCharValueOf & (may be
toNullValueOf()!!!!!!!!)

try the following ex:-
----------------------
there is class "A" having "print" method with "String"
parameter, and then class "B" extending class "A"
having two more methods with the same name ("print")
but with diff type of parameters.

class "Poly" is extending class B (so class A as well)
calling the same method "print" with 3diff parameters,
each time the appropriate method automatically called
by the JVM & executed,,,

 
Answer #9    Answered By: Corey Brown     Answered On: Aug 12

Java does support Polymorphism.Though multiple inheritance is not supported.
What is polymorphism?
The meaning of the word polymorphism is something like one name, many forms.
How does Java implement polymorphism?
Polymorphism manifests itself in Java in the form of multiple methods having the
same name.

In some cases, multiple methods have the same name, but different formal
argument lists (overloaded methods, which were discussed in a previous lesson).
In other cases, multiple methods have the same name, same return type, and same
formal argument list (overridden methods).
Forms of polymorphism
From a practical programming viewpoint, polymorphism manifests itself in three
distinct forms in Java:
Method overloading
Method overriding through inheritance
Method overriding through the Java interface


Please do let me know if any further information is required.

 
Answer #10    Answered By: Fred Hicks     Answered On: Aug 12

Polymorphism has nothing to do with multiple inheritance.

In C++ it is the "virtual" keyword that gives you polymorphism. E.g. an array
of shapes can contain instances of circle, square, triangle, etc, child classes.
(I.e. these classes will all inherit from "shape" as a parent.)

Calling the "draw" method for the items in the array (i.e. at the "shape" level)
will cause the individual "draw" methods for the various children to be used -
provided they are all declared as "virtual".

In C++, methods are not virtual by default, so you need to declare them as such
if you want polymorphic behaviour. In Java, there is no "virtual" keyword, and
polymorphism is the default.

The question of whether Java's interface facility qualifies as polymorphic is a
more vexed one. Inasmuch as it is simply part of the definition of a child
class, it is an integral part of Java's inbuilt polymorphism. When you consider
the ability to attach to different interfaces, that is probably not actually
polymorphic, but it's pretty close.

In fact, my C++ opinion is that Java's interface facility is simply its weird
way of implementing multiple inheritance - once they found that you really
couldn't survive without it.

 
Answer #11    Answered By: Ludo Ricci     Answered On: Aug 12

Java is an object oriented language and the four pillars of Object oriented
language is
1) Inheritence
2) Abstarction
3) Polymorphism
4) Encapsulation

Polymorphism is not related to multiple inheritence... Overloaded methods
explained below is one way Polymorphism is achieved in Java programming

 
Answer #12    Answered By: Luigi Fischer     Answered On: Aug 12

No. Overloaded methods (i.e. selected at compile time) are not polymorphism.
They are simply overloaded methods, but highly useful for all that.

Polymorphism is the late-binding (i.e. at run-time) technique that allows
pointers to child classes of a parent to be kept in a parent class pointer and
for methods defined at the parent level and overridden at the child level to be
called correctly through the parent-level pointer.

The normal use for this is to have an array of related objects and to have the
ability to call common methods at the array level without needing to know the
precise class that the individual objects are members of.

A common example is shapes which can calculate their volume. E.g. "Cube",
"RoundBall", "OvalBall", "Funny19SidedThing" are all shapes (and are therefore
descendents of the "Shape" parent). "Shape" has a "volume" method, but of
course wouldn't have a clue how to calculate a volume. Each child of "Shape"
also has a volume method, which returns the volume of that type of shape.

If you have a collection of RoundBall's, you can simply ask each of the objects
what their volume is - calling the RoundBall.volume method directly.

If, however, you have a collection of Shape's, with items of all the different
types in it, you need to find out which type they are so you can call the
correct "volume" method. Or you can let Java do it for you.

Simply call Shape.volume (i.e. the "volume" method that is visible from the
Shape's collection) and the Java run-time will pass control to the appropriate
"volume" method for you.

The other thing that's great about this is that you can later add
"DonutShapedThing" to your family of Shape's and have it able to live in a
Shape's array and be questioned about its volume, without any changes required
to Shape or any of the other classes.

That's polymorphism. I'm not aware that any of the other techniques are
polymorphic - just useful.

 
Answer #13    Answered By: Latasha Wilson     Answered On: Aug 12

polymorphism is ability of an object to exhibit more than one form.it
mean that depends upon situation the bhavior of the object will be changed.there
are 2 types ploymorphisms exist.
Static polymorphism ------> eg: method overloading
Dyanamic polymorphism--------> eg: Usage of Interfaces
i think it is enough for initial days.for any queries u can call me,take care
,bye

 
Answer #14    Answered By: Ora Hanson     Answered On: Aug 12

My apologies to all that have been offended or
anything in any way SORRY, i had some problems with my
pc it just went *puff* and half of the hardware and
data burnt. At the moment i am using the University
las to work with!!
SORRY AGAIN everyone i just read all the emails
now..GUYS you great thanks for all your help amd sorry
again for not responding back!!

 
Answer #15    Answered By: Angel Watkins     Answered On: Aug 12

I always love to see how people are so ill-intended!
If you want to help and have something to say, do it assuming you are giving
free information with out expecting something back, dam it! Isn't that
supposed to be the purpose of it?

 
Answer #16    Answered By: Burkett Bernard     Answered On: Aug 12

No, replying back that the answer looks good, etc. is helpful because then
you have people answering the same question over and over again
unnecesarily. Also, its just common courtesy. Ya know, close the issue.
Also, if I am doing a search because I have a problem and see lots of posts,
but no resolution I am left deciding if the people answering the person's
email got a good answer that I can also use.

 
Answer #17    Answered By: Perdita Lopez     Answered On: Aug 12

maybe i am understanding you wrong but if i ask a
question and you answer me back by giving you a full
explanation of your question well a bit of gratitude i
should you back dont I? i had some difficulties
answering back in time but i tried to manage as soon
as possible?

 
Answer #18    Answered By: Faith Hughes     Answered On: Aug 12

Let us consider the issue closed. This conversation was becoming
more didactic on "civil courtesy" than "java" (i opened the last few
mails in the hope of getting more insights/perspectives into
Polymorphims, but instead found ppl's views on courtesy).

Privately I concur with Chris that there should be a response from
the person who posts queries. Dunno abt others, but it gives my
vanity a pleasant stimulation to know that my suggestion worked ;-
) . In other cases, when the suggestion is wrong/incomplete, it is a
good learning  experience if the person posts the final answer to his
query.

 
Answer #19    Answered By: Dinh Tran     Answered On: Aug 12

Let's see ... polymorphism is one of the main characteristics of the object
oriented programming paradigm along with inheritance and data encapsulation.
As others have explained polymorphism is the same form with different
shapes, as it pertains to Java, it is just the same name used in different
methods, as in overriding and overloading.

Check
java.sun.com/.../override.html
And
forum.java.sun.com/thread.jspa

 
Answer #20    Answered By: Ann Evans     Answered On: Aug 12

No problem...all it matters now is that I'm done with my 2-3 trees project!
Man that was hard!!!! Specially the deletion and insert methods.

 
Answer #21    Answered By: Dan Romero     Answered On: Aug 12

even though here u will find lotz of techies who
will answer ur question within seconds.. just google
it "Polymorphism" u will find more world class
definitions.. cuz polymorphism is a very common word
OOPS

follwing lines are taken from
http://www.webopedia.com/TERM/p/polymorphism.html

Polymorphism
============
Generally, the ability to appear in many forms. In
object-oriented programming, polymorphism refers to a
programming language's ability to process objects
differently depending on their data type or class.
More specifically, it is the ability to redefine
methods for derived classes. For example, given a base
class shape, polymorphism enables the programmer to
define different area methods for any number of
derived classes, such as circles, rectangles and
triangles. No matter what shape an object is, applying
the area method to it will return the correct results.
Polymorphism is considered to be a requirement of any
true object-oriented programming language (OOPL).

 
Answer #22    Answered By: Clint Garcia     Answered On: Aug 12

Polymorphisms is the feature incorporated in java and many other
languages, which lets you name different functions similarly however
depending upon argument types and/or calling object particular
function is called.

In short, that is many forms but one name.

you can find detailed explanation on java.sun.com

 
Answer #23    Answered By: Wilfred Young     Answered On: Aug 12

No, what you describe is called overloaded methods.
Polymorphism is having two or more classes derived from a base class, and using
a reference to the base class to hold objects of the derived classes.
--
Mark Van Peteghem
http://www.q-mentum.com -- easier and more powerful unit testing

 
Answer #24    Answered By: William Bouchard     Answered On: Aug 12

Polymorphism is a way to abstract the development process of Object
Oriented languages that allows you to decouple the the doing parts of
the code from the conceptual way you design the application.

Most people see Inheritance as polymorphism, which is partially right
from a really limited level; inheritance is a part of polymorphism.

As a really limited example of polymorphism; when you place an object
into a collection of some sort they come back as Object. You have to
tell Java what Object they where before.

CastedObject bob = (CastedObject) i.next();

The ability for all Objects to be treated as Objects is the essence of
polymorphism.

For a really good answer, I would go find a popular book on the matter
(thinking in java, sams java in 24 hours, the complete java reference 2)
and read about it.

Basicaly if you don't understand polymorphism you don't understand OO
programming.

 
Didn't find what you were looking for? Find more on Polymorphism Or get search suggestion and latest updates.

Related Topics:



Tagged:  

 
 
 

Related Post