Is method overloading is an example of runtime polymorphism or compile time polymorphism?
-
Is this homework? A test question? – T.J. Crowder May 06 '10 at 06:57
-
For pity's sake, read your own question before you press the button and correct the mistakes. – DJClayworth Jun 02 '10 at 13:53
4 Answers
There is no operator overloading in Java.
Method overriding enables run-time polymorphism; method overloading enables compile-time polymorphism.
You can read more about this in your textbook.
See also

- 1
- 1

- 376,812
- 128
- 561
- 623
-
Actually, I take back what I said about no operator overloading in Java, e.g. `+` is overloaded for both numeric addition and `String` concatenation (which Josh Bloch suggests may be a mistake by Java designers). So yes, some operators are overloaded in Java, but you can't define _your own_ overloads. – polygenelubricants May 06 '10 at 07:00
Method overloading and polymorphism are two completely different concepts. Polymorphism relates to inheritance and determines from which level of the class hierarchy the method is called. Method overloading is creating two methods in the same location with the same name that take different arguments. For instance:
class A{
public void doSomething(){
System.out.println("A method");
}
//method overloaded with different arguments-- no polymorphism
//or inheritance involved!
public void doSomething(int i){
System.out.println("A method with argument");
}
}
class B extends A{
//method polymorphically overridden by subclass.
public void doSomething(){
System.out.println("B method");
}
}
//static type is A, dynamic type is B.
A a = new B();
a.doSomething(); //prints "B method" because polymorphism looks up dynamic type
//for method behavior

- 14,133
- 7
- 40
- 79
Method overloading is example of complie time binding. Compiler resolves which method needs to be called at compile time only, So it is compile time polymorphism or you can say static binding, But Method overriding is Runtime polymorphism, bcz at run time , depending on the object reference , method call is resolved.

- 83
- 1
- 2
- 9
Method overloading is example for compile time binding or static binding method overloading results in polymorphic methods, a method can be defined more than one time having the same name and varying number either method parameters or parameter types (java allows to do this) , when this happens the linkage between method call and actual definition is resolved at compile time thus overloading is called compile time binding or static binding. OO Program language features call it has compile time Polymorphism.

- 76
- 1
- 3