| Author |
Overloading vs Polymorphism
|
satyanarayana bnv
Greenhorn
Joined: Aug 07, 2008
Posts: 12
|
|
|
What is the exact difference between Overloading and Polymorphism?
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9191
|
|
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.
|
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
|
 |
Brij Garg
Ranch Hand
Joined: Apr 29, 2008
Posts: 234
|
|
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.
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Originally posted by bittoo garg: I dont think there is any term like static polymorphism in java. [/QB]
I Agree This Point
|
 |
Ankit Garg
Saloon Keeper
Joined: Aug 03, 2008
Posts: 9191
|
|
|
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....
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
|
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
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
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
Joined: Jan 28, 2008
Posts: 5575
|
|
Thanks Cambpell
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
|
|
Originally posted by seetharaman venkatasamy: Thanks Cambpell
You're welcome.
|
 |
 |
|
|
subject: Overloading vs Polymorphism
|
|
|