| Author |
Dynamic and Static Polymorphism
|
Raj chiru
Ranch Hand
Joined: Aug 12, 2008
Posts: 140
|
|
Hi..
Is method overloading and method overriding using instance methods are examples of Dynamic polymorphism or Static polymorphism or both?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32660
|
|
I don't like the term "static polymorphism" and would prefer never to use it.
I think all polymorphism is "dynamic" ("runtime" would be a better word) and that is (in Java™) done entirely with method overriding.
Method overloading is probably not polymorphism at all.
Some people say "static polymorphism" which might better be called "compile-time polymorphism" to mean hiding fields and static methods by declaring fields and static methods with the same name/signature. If you look in books like Effective Java by Bloch or our FAQ (no 16) you can find out how much confusion that can cause.
It may be possible to implement compile-time polymorphism in other languages than Java.
|
 |
Raj chiru
Ranch Hand
Joined: Aug 12, 2008
Posts: 140
|
|
Hi..campbell
why method overloading is not involved with polymorphism?
|
 |
Varun Goenka
Ranch Hand
Joined: Mar 09, 2009
Posts: 37
|
|
Raj please note this polymorphism is a concept that deals with "same" methods in "different" classes.
Polymorphism is what happens; when you call a method, on a reference; that happens to be of a class that has been extended to another class having that method.
Well.....thats technically correct but lets be frank that sentence will take some time to understand.
But you can always rote learn that sentence and give it to your professor .
|
From The Demon,
with love.
|
 |
Varun Goenka
Ranch Hand
Joined: Mar 09, 2009
Posts: 37
|
|
Method overloading deals with 2 different methods in the same class, while overriding deals with the same method present in different classes.
Polymorphism deals with the latter.
|
 |
 |
|
|
subject: Dynamic and Static Polymorphism
|
|
|