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
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
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).
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
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.
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
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.