• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Overloading vs Polymorphism

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the exact difference between Overloading and Polymorphism?
 
Sheriff
Posts: 9680
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well actually you can compare Overloading and Overriding.



The above three are overloaded methods as they have the same name but have different parameters. Overloaded methods have static polymorphism as their calls are bound at compile time. So if you call these as
add(1.2f, 3.5f); //calls 3
add(2,3); //calls 1
add(1,2,3); //calls 2




The above is overriding. method marked as 2 is overriding method marked as 1 as they have same name and parameters. Their calls are bound to appropriate methods at run-time. So they are dynamically polymorphic.
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

overloading:- method is invoked at run time on the basis of type of reference variable.
overriding:- method is invoked at run time on the basis of type of the object reference variable is refering to.

I dont think there is any term like static polymorphism in java.
Overriding is polymorphism.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by bittoo garg:


I dont think there is any term like static polymorphism in java.
[/QB]



I Agree This Point
 
Ankit Garg
Sheriff
Posts: 9680
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is just called as static polymorphism. I also know that it is not polymorphism. But since the method name is same and parameters are changed, it is called static polymorphism as compiler can detect which method will be called. At least it was called static polymorphism when we used to study C++ in our school days....
 
Marshal
Posts: 72921
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here, Ernest Friedmann-Hill says he dislikes a term, I think "compile-time polymorphism" and I think I shall take a disliking to "static polymorphism" for the same reason.
 
Campbell Ritchie
Marshal
Posts: 72921
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by myself:
Here, Ernest Friedmann-Hill says he dislikes a term, I think "compile-time polymorphism" and I think I shall take a disliking to "static polymorphism" for the same reason.



Bittoo Garg, I think you are right on that point.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Cambpell
 
Campbell Ritchie
Marshal
Posts: 72921
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by seetharaman venkatasamy:
Thanks Cambpell

You're welcome.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic