• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dynamic and Static Polymorphism

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..campbell
why method overloading is not involved with polymorphism?
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic