0

Can any one explain me how overloading is a compile time polymorphisam?

10th Mar 2016, 9:19 AM
Swapnil Gapchup
Swapnil Gapchup - avatar
2 Answers
+ 1
Example: class A { public void someMethod() { } } class B extends class A { public void someMethod() { /*This method overrides the method in class A */ } public void methodOverload(int x, double y) { //... } public void methodOverload(double c) { //... } } class HomeBase { public static void main(String[] args) { B objectB = new B( ); objectB.methodOverload(6, 3.14); /* The compiler determines the 2-parameter methodOverload(int x, double y) is the correct choice at compile time. The choice is clear even before objectB is created. */ objectB.someMethod(); /*The program cannot decide which someMethod() to use until it creates the objectB at runtime. */ } }
23rd Apr 2016, 10:08 AM
ic01010101 ◌LM
ic01010101 ◌LM - avatar
0
Hi, Method overloading is a compile time polymorphism because the method to be executed is chosen at runtime - based on the arguments.
2nd May 2016, 11:03 AM
Ateeb
Ateeb - avatar