wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Polymorphism Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Polymorphism" Watch "Polymorphism" New topic
Author

Polymorphism

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi all,
Could someone explain the Polymorphism to me with some examples?
I really want to know the definition of Polymorphism and how we can use it.
Thank you in advance.
Mike
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

Def.:
ability of an obj to respond to a message in a
manner appropriate to its type.
Ex: In this example, you could see which method
gets called. The method of the class to which
the object belongs to gets called.

If you are familiar with C++ the same is achieved
using the keyword virtual.
Regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
thejus/mahesh
Greenhorn

Joined: Aug 21, 2000
Posts: 19
hi mike
polymorphism is a oops concept where function/object act differently according to the situations
for example
add(int a,int b);
add(int a,float b);
add(double d,double x);
see here add function will act differently according to the parametes passed to the add function
this is checked only during runtime. it is taken care by jvm
this in brief polymorphism
hope i am clear if not please get back
regds
thejus/mahesh
Netla Reddy
Greenhorn

Joined: Jun 18, 2000
Posts: 15
Hi All,
Polymorphism:One or more object act diferently for same message.
Take one real world example
Suppose one Car (Car Object) , one Cycle (One more object) are running on the road and they reached a signal and with red sign both object will stop.
Here both objects are stopped for one message but the mechanism is different.
I hope it is clear for you.............

Please notice that there are two types of Polymorphism Viz
1) Static Polymorphism and Dynamic Polymorphism or
2) True Polymorphism or False Polymorphism or
4) Compile Polymorphism or Runtime Polymorphism



 
 
subject: Polymorphism