Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamic and Static Polymorphism

 
Raj chiru
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
Is method overloading and method overriding using instance methods are examples of Dynamic polymorphism or Static polymorphism or both?
 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..campbell
why method overloading is not involved with polymorphism?
 
Varun Goenka
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 .
 
Varun Goenka
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic