+ 1
How compile-time polymorphism is overloading and runtime polymorphism is overriding ??? Can anyone explain me here.
4 ответов
+ 1
I think Overloading means: make one more method which mustn't has same return type and parameter type,
Overriding is just move into memory, it is not change the parent's method, just create a new method in the memory instead of the old function
+ 1
Compile Time Polymorphism: Whenever an object is bound with their functionality at the compile-time, this is known as the compile-time polymorphism. At compile-time, java knows which method to call by checking the method signatures. So this is called compile-time polymorphism or static or early binding. Compile-time polymorphism is achieved through method overloading. Method Overloading says you can have more than one function with the same name in one class having a different prototype. Function overloading is one of the ways to achieve polymorphism but it depends on technology that which type of polymorphism we adopt. In java, we achieve function overloading at compile-Time. The following is an example where compile-time polymorphism can be observed.
+ 1
Run-Time Polymorphism: Whenever an object is bound with the functionality at run time, this is known as runtime polymorphism. The runtime polymorphism can be achieved by method overriding. Java virtual machine determines the proper method to call at the runtime, not at the compile time. It is also called dynamic or late binding. Method overriding says child class has the same method as declared in the parent class. It means if child class provides the specific implementation of the method that has been provided by one of its parent class then it is known as method overriding. The following is an example where runtime polymorphism can be observed.