GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 443 of 502    Print  
What is the difference between Static and Dynamic Polymorphisim?

  
Total Answers and Comments: 7 Last Update: January 05, 2009     Asked by: gmalcomfernandez 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: interviewprep9
 
Polymorphism means existing in various forms.

1).Method Overloading: For example, Same method name and different parameters. Here the method is existing in various forms.

2).Method Overriding: You get a method in your class from it's parent class and you override it(Add your own fucntionality to it). Here also you are using same method name for two diffrent purposes.

Here, however tho JVM at runtime calls the parent class method if you don't add your own fucntionalty(don't override the parent class method). But if you do override the parent class methods, JVM invokes the child class's method. Since this is done at runtime, it's called as runtime polymorphism or dynamic polymorphism.

There is no such decision making in method overloading so it is called as static polymorphism or compile time polymorphism.

Thx.

Above answer was rated as good by the following members:
Sureshpdn
October 11, 2007 05:01:52   #1  
harirathod123 Member Since: May 2006   Contribution: 1    

RE: What is the difference between Static and Dynamic ...
method overloading would be an example of static polymorphism
whereas overriding would be an example of dynamic polymorphism.

B'Coz in case of overloading at compile time the compiler knows which method to link to the call .
However it is determined at runtime for dynamic polymorphism

 
Is this answer useful? Yes | No
November 27, 2007 00:49:38   #2  
shivkant.pawan Member Since: November 2007   Contribution: 5    

RE: What is the difference between Static and Dynamic ...
method overloading is an example of compile time/static polymorphism because method binding b/w method call and method defination happens at compile time and it's depend on the ref. of the class(ref. create at copile time and goes to stack).

method overriding is an example of run time/dynamic polymorphism because method binding b/w method call and method defination happens at run time and it's depend on the object of the class(object create at time and goes to heap).

 
Is this answer useful? Yes | No
February 14, 2008 01:09:51   #3  
sampra Member Since: February 2008   Contribution: 278    

RE: What is the difference between Static and Dynamic Polymorphisim?
static polymor is compile time polymorphism ie method overloading
dyanmic polymorphism is rumtime polymorphism ie method overriding+dynamic dispatch

 
Is this answer useful? Yes | No
June 09, 2008 04:58:08   #4  
kiranmai.kasturi Member Since: June 2008   Contribution: 4    

RE: What is the difference between Static and Dynamic Polymorphisim?
Static polymarphism is compile time polymarphis i.e if we take method overloading at copile time itself method call will bound to method definition. Dynamic polymarphism is runtime polymarphism i.e if we take method overriding method call bound to method def at runtime depends on object reference
 
Is this answer useful? Yes | No
June 16, 2008 16:58:30   #5  
interviewprep9 Member Since: June 2008   Contribution: 10    

RE: What is the difference between Static and Dynamic Polymorphisim?
Polymorphism means existing in various forms.

1).Method Overloading: For example Same method name and different parameters. Here the method is existing in various forms.

2).Method Overriding: You get a method in your class from it's parent class and you override it(Add your own fucntionality to it). Here also you are using same method name for two diffrent purposes.

Here however tho JVM at runtime calls the parent class method if you don't add your own fucntionalty(don't override the parent class method). But if you do override the parent class methods JVM invokes the child class's method. Since this is done at runtime it's called as runtime polymorphism or dynamic polymorphism.

There is no such decision making in method overloading so it is called as static polymorphism or compile time polymorphism.

Thx.

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
January 03, 2009 03:57:30   #6  
santhu_chantti Member Since: October 2008   Contribution: 3    

RE: What is the difference between Static and Dynamic Polymorphisim?
Static polymorphism is code refinement and where as runtime polymorphism is code replacement.


Static polymorphism is achieved by method overloading and runtime polymorphism is achieved by method overriding.


To implement static polymorphism inheritance is not necessary but to implement runtime polymorphism inheritance is necessary.


Generally when programmer needs to extend existing feature available in software method overloading is used but a programmer uses method overriding when he wants to provide a different implementation for the same feature


 
Is this answer useful? Yes | No
January 04, 2009 22:48:53   #7  
bhaumiklitu Member Since: March 2008   Contribution: 4    

RE: What is the difference between Static and Dynamic Polymorphisim?
The term static polymorphism is associated with overloaded methods because it gives the impression that a single named method will accept a number of different argument types. The System.out.println() method is an example that may take String or Object references boolean and other primitive types as an argument. In fact each overloaded method is separate and the compiler can see the difference between them. In this case the argument types are fixed at compile time and are considered static. This has nothing to do with the Java keyword static.

Dynamic polymorphism is where a class overrides a superclass method or implements an interface. For example any class may override the Object.toString() method and provide its own implementation and this is known at compile time. However for a simple Java program that instantiates a series of objects and calls their toString() method the compiler does not consider the object references differently. Any differences in the objects' toString() implementations are only seen at runtime so they are considered dynamic.


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape