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 (1720)
 Advanced Java interview questions  Advanced Java Interview Questions (331)
 Swing interview questions  Swing Interview Questions (43)
 EJB interview questions  EJB Interview Questions (134)
 Servlets interview questions  Servlets Interview Questions (255)
 Struts interview questions  Struts Interview Questions (195)
 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 (145)
 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 :: Gopalraop
I also faced this Question!!     Rank Answer Posted By  
 
  Re: what is polymorphism with example?types of polymorphism?
Answer
# 1
It is reacting differently for the same kind of message.

For example,

Consider Parrot,Penguin & tiger

My message is "approach me quickly"

Their different reactions:

Parrot approaches me by " flying"
Penguin approaches me by "swimming"
Tiger approaches me by "running"

Here my message is simply "pproach me quickly"
But different things have been reacted differently.

This is called Polymorphism.

As far as my knowledge is concerned there is only one type
of polymorphism and that is runtime polymorphism.
 
Is This Answer Correct ?    69 Yes 88 No
Sandeep
 
  Re: what is polymorphism with example?types of polymorphism?
Answer
# 2
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
 
 
 
  Re: what is polymorphism with example?types of polymorphism?
Answer
# 3
Three types

1) Method Overloading
2) Method Overriding
3) Interface
 
Is This Answer Correct ?    51 Yes 103 No
Sachin
 
  Re: what is polymorphism with example?types of polymorphism?
Answer
# 4
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
 
  Re: what is polymorphism with example?types of polymorphism?
Answer
# 5
same name multiple form is call poly...

static polymorphism and dynamic polymorphism.
 
Is This Answer Correct ?    71 Yes 13 No
Nikunj B Patel
 
  Re: what is polymorphism with example?types of polymorphism?
Answer
# 6
Polymorphism means one word having different meaning at
different instances.
There are two types.
1)Method overloading
2)Method overriding
 
Is This Answer Correct ?    25 Yes 39 No
Barkha
 
  Re: what is polymorphism with example?types of polymorphism?
Answer
# 7
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
 
  Re: what is polymorphism with example?types of polymorphism?
Answer
# 8
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
 
  Re: what is polymorphism with example?types of polymorphism?
Answer
# 9
two types
1.static
2.dynamic
 
Is This Answer Correct ?    39 Yes 13 No
Gupta
 
  Re: what is polymorphism with example?types of polymorphism?
Answer
# 10
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
 

 
 
 
Other Core Java Interview Questions
 
  Question Asked @ Answers
 
What are listeners in java and explain ? TCS 2
what is Abstract DataType?   1
what is purpose of writting public static void main(Strind arg[]) in java..? ITC-Infotech 4
why java main method is given as static method?   2
any other way to print the text without using System.out.println() in java? Ibm 4
In treeset we add same object ...what will be the out put   3
My application URL : http://localhost:8080/Application/Login.jsp. When a user enter this url in IE then, how it get Login.JSP Page exactly? what are the processes will happen from when we submit the URL to get Login.jsp? TCS 3
why operator overloading is removed in java?   1
class A{ class B{ } } in which name u save the file,its the program compile? HCL 6
steps to connect with Oracle Databse using TYPE-2 Jdbc driver.   3
What is the reason that multiple inheritance is not possible in java??   1
If all the methods in abstract class are declared as abstract then what is difference between abstract class and in interface? Synechron 7
 
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