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 (1721)
 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 (146)
 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
 
How many ways can an argument be passed to a subroutine? Technological-University-of-the-Philippines 3
I need to know about complete topic in java's collections i with an examples TCS 1
What is a void return type?   6
Why non nested classes in java are not having marked as protected access specifier Google 2
can any one tell me when do u go for inheritance and polymorphism   3
Create a form of user Login in JSP, that accepts the user name and password from user and authenticate it with user names and passwords stored in database. (Plz provide me answer immediately) ABC 1
What is a reflection package?   2
What are wrapper classes? Noah-Solutions 11
how can be object class inherited to all class in a program when java does not support multiple inheritance??   4
I have an HashMap object, which has with key and value pair. It has 10 keys and values in that object. Now the question is I want insert new key and value in middle or any where in that list but not at the end or at the top. Is it possible or not. If yes how can we achieve this one? Huawei 2
why top level class could not be static L&T 2
A class can be a subclass of itself? Genesis 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