what is polymorphism with example?types of polymorphism?

Answers were Sorted based on User's Feedback



what is polymorphism with example?types of polymorphism?..

Answer / ramaraju

polymorphism means "same thing will exists with different
forms"

Ex :suppose we need to find volume of
circle,rectangle,triangle.ect in a sampe program.

genrally what we need to do is write the code volume for
cirle,rectangle,triangle in sepratly.
using polymorphism concept we simply write the volume code
with different parameter list ect

Ex:

class a {

volume(int a)//for rectangle
{
---
}
volume (int a,intb,intc)//for triangle
{

--
}

volume (string s)//for circle
{
--
}

}end of class A

polymorphisam are mainly two types
static polymorphisam(corresponding method will bind at the
time of compiling)
dynamic polymorphisam(corresponding method will bind at the
run time)

Is This Answer Correct ?    162 Yes 18 No

what is polymorphism with example?types of polymorphism?..

Answer / nikunj b patel

same name multiple form is call poly...

static polymorphism and dynamic polymorphism.

Is This Answer Correct ?    71 Yes 13 No

what is polymorphism with example?types of polymorphism?..

Answer / gupta

two types
1.static
2.dynamic

Is This Answer Correct ?    39 Yes 13 No

what is polymorphism with example?types of polymorphism?..

Answer / amr

well Polymorphism means one name implies many forms , which introduces generic programming . Polymorphism happens in the inheritance hierarchy , so that low level abstractions which extend higher level abstraction can override
(re-implementing a method of superclass in a subclass with identical signature) the implementation of the higher level abstraction .

example :

class vehicle {
void accelerate()
}

class car extends vehicle{
void accelerate()
{
S.O.P("um a car");
}
}
class bike extends vehicle{
void accelerate()
{
S.O.P("um a bike");
}
}

now bike and car vehicles .
so we can say

Vehicle[] v = new Vehicle[2];
v[0]= new Car();
v[1]=new Bike();

so here i have array of vehicles
i can do the following (generically )

for (i=0;i<v.length;i++)
v[i].accelerate();
-------
output:
um a car
um a bike

like i say ok guys all of u r vehicles so all of u can accelerate so do it everyone on his own way .

now that was a very polymorphic piece of code
because every time i call the method accelerate on an object the JVM will do Dynamic resolution and invoke the corresponding method of that object .

so not only overriding is polymorphic but we should keep a consistent inheritance hierarchy or abstraction levels .

---

method overloading is another form of polymorphism but its easier to implement because at compilation time all the method calls are resolved .

for ex
-----

class Add {

int add(int a, int b)
{
return a+b;
}
float add(float a,float b)
{
return a+b;
}
}
so be careful with overloading because methods are identified by it signature which is
-return type
-name
-parameters number
-parameters types
-order of parameters

since overloading means the same name then we are left with
-return type
-parameters number
-parameters types
-order of parameters

now lets see this code

Add a = new Add();
int x =a.add( 2 , 3 );
float y = a.add( 2.2, 3.4);
-----------

now i guess this covers the polymorphism types
what do u say

Is This Answer Correct ?    39 Yes 16 No

what is polymorphism with example?types of polymorphism?..

Answer / hassan arafat

Polymorphism allows an entity (for example, variable,
function or object) to take a variety of representations.

Ad-hoc polymorphism: This polymorphism let a function to
have different implementations based on its parameters and
return type. Ad-hoc polymorphism is supported through
function and method overloading.
Parametric polymorphism: lets you write a piece of code
that is not associated with a particular type and therefore
can be used with any type. Object oriented languages like
C# achieve it through generics.
Inclusion polymorphism: let a type hold instances of many
different types as long as the types are related by some
common parent class. Object oriented languages like C#
achieve inclusion polymorphism through inheritance.

Is This Answer Correct ?    33 Yes 11 No

what is polymorphism with example?types of polymorphism?..

Answer / ramaiah.teepalapudi

polymorphism is the phenomenon where the same message sent
to two different objects produces two different set of
actions. Polymorphism is broadly divided into two parts:



Static polymorphism – exhibited by overloaded functions.
Dynamic polymorphism – exhibited by using late binding.

Is This Answer Correct ?    29 Yes 7 No

what is polymorphism with example?types of polymorphism?..

Answer / nidhi joon

The ability to take more than one form.
Supports two type
Method Overloading
Method Overriding

Is This Answer Correct ?    58 Yes 38 No

what is polymorphism with example?types of polymorphism?..

Answer / vignesh,c

poly means many morph means shapes so, one function taking
many shapes ,for ex: take the function name as add,
by passing different sets of arguments it can add 2no.s,3
numbers etc....

there are two types of polymorphism namely,
runtime polymorphism,compile time polymorphism,
compile time Polymorphism means function overloading,
run time polymorphism means virtual functions.

Is This Answer Correct ?    4 Yes 0 No

what is polymorphism with example?types of polymorphism?..

Answer / prashantshukla

the types of polymorphism
compile time
run time

Is This Answer Correct ?    5 Yes 1 No

what is polymorphism with example?types of polymorphism?..

Answer / vignesh,c

poly means many morph means shapes so, one function taking
many shapes ,for ex: take the function name as add,
by passing different sets of arguments it can add 2no.s,3
numbers etc....

there are two types of polymorphism namely,
runtime polymorphism,compile time polymorphism,
compile time Polymorphism means function overloading,
run time polymorphism means virtual functions.

Is This Answer Correct ?    3 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is java object name?

0 Answers  


What is the difference between throw and throws keywords?

0 Answers  


Is there a way to increase the size of an array after its declaration?

0 Answers  


What is charat ()?

0 Answers  


How many bytes is a char in java?

0 Answers  






what is the life cycle of jsp?

3 Answers   Photon,


what is jdk1.5 features?

6 Answers   AMS, Virtusa,


what are the rules to use try catch finally?

1 Answers   Satyam, UJ,


What is method Overriding in the perspective of OOPS?

4 Answers   TCS,


What is lifetime variable?

0 Answers  


What does nullpointerexception mean?

0 Answers  


can we create object for static class in java

14 Answers   IAP Company, IBM, Marlabs, mPortal, TCS,


Categories