Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Overloaded Methods in Java are early binded or late binded

 
Amar Shrivastava
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amar Shrivastava
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic