ALLInterview.com :: Home Page            
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
Google
   
 
Categories >> Software >> Java Related >> Java J2EE >> Core Java
 
 


 

 
 Core Java interview questions  Core Java Interview Questions (1722)
 Advanced Java interview questions  Advanced Java Interview Questions (331)
 Swing interview questions  Swing Interview Questions (44)
 EJB interview questions  EJB Interview Questions (134)
 Servlets interview questions  Servlets Interview Questions (255)
 Struts interview questions  Struts Interview Questions (196)
 JDBC interview questions  JDBC Interview Questions (187)
 JMS interview questions  JMS Interview Questions (9)
 SunOne interview questions  SunOne Interview Questions (3)
 J2EE interview questions  J2EE Interview Questions (71)
 Weblogic interview questions  Weblogic Interview Questions (147)
 Websphere interview questions  Websphere Interview Questions (14)
 Java Networking interview questions  Java Networking Interview Questions (20)
 Java J2EE AllOther interview questions  Java J2EE AllOther Interview Questions (87)
Question
what is polymorphism with example?types of polymorphism?
 Question Submitted By :: Core-Java
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
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 ?    159 Yes 17 No
Ramaraju
 
Answer
# 2
same name multiple form is call poly...

static polymorphism and dynamic polymorphism.
 
Is This Answer Correct ?    71 Yes 13 No
Nikunj B Patel
 
 
 
Answer
# 3
two types
1.static
2.dynamic
 
Is This Answer Correct ?    39 Yes 13 No
Gupta
 
Answer
# 4
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
Amr
 
Answer
# 5
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
Hassan Arafat
 
Answer
# 6
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
Ramaiah.teepalapudi
 
Answer
# 7
The ability to take more than one form.
Supports two type
Method Overloading
Method Overriding
 
Is This Answer Correct ?    58 Yes 38 No
Nidhi Joon
 
Answer
# 8
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
Vignesh,c
 
Answer
# 9
the types of polymorphism
compile time
run time
 
Is This Answer Correct ?    5 Yes 1 No
Prashantshukla
 
Answer
# 10
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
Vignesh,c
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
Does 'true' and 'false' are keywords?   5
Can we declare static variables in JSP page. TCS 3
How many objects are created when we create String class object using new operator? Mind-Tree 7
How will you convert an ArrayList to Arrays? KPIT 4
What is the difference between Byte stream and Charecter Stream? Tarang-Software 2
what difference between throw and throws in exception handling.   5
What is the use of anonymous inner classes ? HCL 12
Difference between Application and Applet ? Wipro 4
what are the rules to use try catch finally? Satyam 1
What are uses of Hash Code? Cognizent 2
How can we handle runtime exceptions? write one sample program? Can we write runtime exceptions beside the throws key word? if yes write sample program? Huawei 1
Are nested try statements are possible?   2
 
For more Core Java Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com