Hi, I need detailed explanation of difference between compile time polymorphism and run time polymorphism?. How complie time polymorphism and run time polymorphism is achieved. Can any body explain with detailed example.
There is no anology like compile time polymorphism, polymorphism only happen run time. Try this: 1] create a class, declare one method in it. 2] create another class that extends previous one and override that method. 3] write main method in second class, and in that, assign sub class object to super class reference. 4] call that method.
what happens, at compile time, it is binded to reference and at run time it is binded to object and thatswhy the overriding method gets execute.
//output is: test() is overriding method But my doubt is: deciding which method to be called during compile time is compile time polymorphism. ex: Sub ob = new Sub(); //This is example for compile time polymorphism.
Deciding which method to be called at runtime is runtime polymorphism. Super ob = new Sub();//Example for runtime polymorphism.Thanks for spending your most valuable time for giving response.
subject: Complie time polymorphism vs Runtime polymorphism