| Author |
Overloaded Methods in Java are early binded or late binded
|
Amar Shrivastava
Greenhorn
Joined: Oct 17, 2005
Posts: 13
|
|
Hi All During my recent interviews I was asked about Polymorphism and early binding and late binding. Every time I said that overloaded methods implementations are binded dynamically during runtime until the method is static or final(private are implictly final). But every time I was told by the interviewers that overloaded methods are early binded. Could you please suggest what is correct with overloaded methods and Why? [ October 17, 2005: Message edited by: Amar Shrivastava ]
|
 |
Sabarish Sasidharan
Ranch Hand
Joined: Aug 29, 2002
Posts: 73
|
|
|
If you are talking about overloading, then yes, there is no dynamic binding involved... So i can agree with your interviewers. On the other hand overriding requires runtime binding.
|
Sab<br /> <br />Perfection does not come from belief or faith. Talk does not count for anything. Parrots can do that. Perfection comes through selfless work.<br />Swami Vivekananda
|
 |
Amar Shrivastava
Greenhorn
Joined: Oct 17, 2005
Posts: 13
|
|
But how could you ever say that the overloaded method will not be overridden in the subclasses. Let's say: public class A{ int x(String s){...} int x(int i){...} void x (String s, int i){} .... .... } public class B extends A{ int x(String s){...} int x(int i){...} void x (String s, int i){} ...... .... } class Client { public static void main(String []args){ A a= new B(); a.x("java"); } } In this case looking at class A alone which does not no that it has a sub class and the class Client uses a class A reference and calls a method x. Now how could this be resolved at compile time.
|
 |
Andrew Monkhouse
author and jackaroo
Marshal Commander
Joined: Mar 28, 2003
Posts: 9982
|
|
Moved to Java in General (Intermediate). I am not sure that it belongs there, but that is where your other copy of the same question is. In future, please Carefully Choose One Forum. You can find the new version here. [ October 17, 2005: Message edited by: Andrew Monkhouse ]
|
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
|
 |
 |
|
|
subject: Overloaded Methods in Java are early binded or late binded
|
|
|