GeekInterview.com
Series: Subject:
Question: 249 of 271

What are the different types of polymorphism?

Asked by: Interview Candidate | Asked on: Sep 1st, 2005
Showing Answers 1 - 19 of 19 Answers
capreatki

Answered On : Jul 19th, 2005

two.. one is RUNTIME Polymorphism which includes virtual functions etc and another is COMPILE TIME Polymorphism which includes function overloading etc..

Yes  1 User has rated as useful.
  
Login to rate this answer.
Amit Banerjee

Answered On : Sep 1st, 2005

Two types of polymorphism: 
1. Static Polymorphism (Early binding) 
2. Dynamic Polymorphism (Late binding)

Yes  1 User has rated as useful.
  
Login to rate this answer.

capreatki Wrote: two.. one is RUNTIME Polymorphism which includes virtual functions etc and another is COMPILE TIME Polymorphism which includes function overloading etc..

Can u give brief idea, how it is possible to implement compile time polymorphism(method overloading or operator overloading)... without creating object... How it is maintaining virtual tables....

  
Login to rate this answer.
Yashwant S pinge

Answered On : Mar 27th, 2006

hello,There are two types of polymorphism as shown above.static polymorphism :-- operator oveloading and function overloading.dynamic plymorphism :- virtual functionality

  
Login to rate this answer.
sapam james

Answered On : Nov 8th, 2006

Polymorphism is mainly divided into :

1) Run Time polymorphism: a) Virtual function

2) Compile Time Polymorphism : a) function overloading

                                           b) operator overloading

  
Login to rate this answer.
remya_rajan

Answered On : Apr 2nd, 2009

View all answers by remya_rajan

There are 2 types of Polymorphism
1. Compile time Polymorphism
2. Run Time Polymorphism
Compile time polymorphism is used for Function overloading
Runtime is used for implementing virtual functions,overriding etc.

Yes  1 User has rated as useful.
  
Login to rate this answer.
knicholes

Answered On : Oct 2nd, 2010

View all answers by knicholes

There are FOUR kinds of polymorphism

1.  Overloading  (Same function names, different parameter types.  This includes operator overloading and is done at compile time)

1.  Parametric polymorphism  (These are like templates in C++)  Compile time

3.  Subtype polymorphism (if a function has a parameter with a subtype, for example Car->Honda, f(Car), then function f will accept f(Honda) as well.)  Runtime

4.  Parameter coercion  (This is an implicit type conversion.  For example, a function might require a double/real/float, but will accept an int and will implicitly upcast the parameter)
Compile time

Yes  1 User has rated as useful.
  
Login to rate this answer.
jimasp

Answered On : Oct 22nd, 2010

View all answers by jimasp

knicholes answer is correct. I would also add that Overloading in this context is also known as "ad hoc polymorphism".

If you want to be picky, there are probably more specific types of polymorphism too, but they are best left to the academics (have a look at http://en.wikipedia.org/wiki/Type_polymorphism).

  
Login to rate this answer.
Lawren Arumai

Answered On : Apr 24th, 2011

View all answers by Lawren Arumai

static polymorphism and dynamic polymorphism.
method overloading---static polymorphism
method overriding------dynamic polymorphism(later binding)

  
Login to rate this answer.

There are two types of Polymorphism
1. Run time polymorphism.
2. Compile Time Polymorphism

Run Time Polymorphism is inplemented by Virtual functions and Compile Time Polymorphism is implemented by function overloading.

  
Login to rate this answer.
sai

Answered On : Jul 13th, 2011

Hi! friends this Praveen From Hyderabad. There are two types of polymorphism 1. Dynamic polymorphism(run time or dynamic binding): the polymorphism exhibited at run time is called dynamic polymorphism. this means when a method is bound to the method body at the time of running the program,dynamically. Here the java compiler does not decide which method id called at compilation time, jvm decides which method is called at run time. We can achieve Dynamic Polymorphism by using overloading and overriding on instance variables and concrete methods. 2. Static polymorphism(compile time or static binding): the polymorphism exhibited at compile time is called static polymorphism. Here the java compiler decides which method id called at compilation time. We can achieve static Polymorphism by using overloading and overriding on static methods.

Code
  1. // this is the method overloading concept example
  2. class Poly
  3. {
  4. void cal(int a,int b)
  5. {
  6. System.out.println(" Sum of two numbers : "+(a+b));
  7. }
  8. }
  9.  
  10. class Poly1 extends Poly
  11. {
  12. void cal(int a,int b)
  13. {
  14. System.out.println(" Product of two numbers : "+(a*b));
  15. }
  16. }
  17. class Demo1
  18. {
  19. public static void main(String args[])
  20. {
  21. Poly1 p1=new Poly1();
  22. p1.cal(10,20);
  23.  
  24. }
  25. }
  26.  

  
Login to rate this answer.
Anita

Answered On : Aug 2nd, 2011

this program is for method overriding not for overloading

Code
  1. #
  2. class Poly
  3.  
  4. #
  5. {
  6.  
  7. #
  8. void cal(int a,int b)
  9.  
  10. #
  11. {
  12.  
  13. #
  14. System.out.println(" Sum of two numbers : "+(a+b));
  15.  
  16. #
  17. }
  18.  
  19. #
  20. }
  21.  
  22. #
  23.  
  24.  
  25. #
  26. class Poly1 extends Poly
  27.  
  28. #
  29. {
  30.  
  31. #
  32. void cal(int a,int b)
  33.  
  34. #
  35. {
  36.  
  37. #
  38. System.out.println(" Product of two numbers : "+(a*b));
  39.  
  40. #
  41. }
  42.  
  43. #
  44. }
  45.  
  46. #
  47. class Demo1
  48.  
  49. #
  50. {
  51.  
  52. #
  53. public static void main(String args[])
  54.  
  55. #
  56. {
  57.  
  58. #
  59. Poly1 p1=new Poly1();
  60.  
  61. #
  62. p1.cal(10,20);
  63.  
  64. #
  65.  
  66.  
  67. #
  68. }
  69.  
  70. #
  71. }

  
Login to rate this answer.
WF

Answered On : Aug 29th, 2011

SNPs, RFLPs, STRs, VNTRs

  
Login to rate this answer.
nagtan3

Answered On : Oct 24th, 2011

View all answers by nagtan3

This is not overloading, but overriding !!!

Code
  1.  
  2. class Poly
  3. {
  4. void cal(int a,int b)
  5. {
  6. System.out.println(" Sum of two numbers : "+(a+b));
  7. }
  8. }
  9.  
  10. class Poly1 extends Poly
  11. {
  12. void cal(int a,int b)
  13. {
  14. System.out.println(" Product of two numbers : "+(a*b));
  15. }
  16. }
  17. class Demo1
  18. {
  19. public static void main(String args[])
  20. {
  21. Poly1 p1=new Poly1();
  22. p1.cal(10,20);
  23.  
  24. }
  25. }

  
Login to rate this answer.
kaiza fadhili

Answered On : Apr 23rd, 2012

* Compile time Polymorphism
* Run time Polymorphism

  
Login to rate this answer.
Akash Singhal

Answered On : May 17th, 2012

Polymorphism means ability to take more than one form.

Overloading is an example of compile time polymorphism.(Because the function to call is decide at compile time)
Overriding an example of compile time polymorphism.(Because the function to call is decide at runtime)

Overloading:

Math math=Math();
math.add(10,20)
math.add(10,20,30)

Overriding:

superclassObject.add(10,10)
subclassObject.add(10,10)

Here in the case of Overriding the method which will call is decide will decide at the runtime.

  
Login to rate this answer.
sandeep

Answered On : Sep 16th, 2012

1. Static Polymorphism (Early binding)
2. Dynamic Polymorphism (Late binding)

  
Login to rate this answer.
kutty

Answered On : Sep 24th, 2012

how to write a simple java programs for overloading & overriding

  
Login to rate this answer.
Have Fun

Answered On : Dec 28th, 2012

Two:
Ad-hoc polymorphism and universal polymorphism

  
Login to rate this answer.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.