Difference between function overloading and polymorphism in c++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Difference between function overloading and polymorphism in c++

22nd Apr 2019, 8:30 AM
Thanneeru Mohan Reddy
Thanneeru Mohan Reddy - avatar
6 Answers
+ 13
Function overloading is sometimes called compile time polymorphism but runtime polymorphism achieved through method overriding is what's important in OOP.
22nd Apr 2019, 11:43 AM
Sonic
Sonic - avatar
+ 13
Polymorphism is the technique of defining a common interface for a hierarchy of classes. To support this, a derived object is allowed wherever a base object is expected. A derived class may redefine inherited member functions, overriding any function with the same name, parameters, return type, and const-ness (and hiding other functions with the same name, thus the overriding function should not be overloaded).
22nd Apr 2019, 11:53 AM
Danijel Ivanović
Danijel Ivanović - avatar
+ 4
Polymorphism can be achieved through overriding. Put in short words, polymorphism refers to the ability of an object to provide different behaviors (use different implementations) depending on its own nature. Specifically, depending on its position in the class hierarchy. Method Overriding is when a method defined in a superclass or interface is re-defined by one of its subclasses, thus modifying/replacing the behavior the superclass provides. The decision to call an implementation or another is dynamically taken at runtime, depending on the object the operation is called from. Notice the signature of the method remains the same when overriding. Method Overloading is unrelated to polymorphism. It refers to defining different forms of a method (usually by receiving different parameter number or types). It can be seen as static polymorphism. The decision to call an implementation or another is taken at coding time. Notice in this case the signature of the method must change.
22nd Apr 2019, 8:56 AM
Kartik
Kartik - avatar
+ 2
POLYMORPHISM is of two types , Function overloading that is also called method overloading and second is Method Overriding. In FUNCTION OVERLOADING, Methods have same name with different number of arguments or with different data types also. In METHOD OVERRIDING, Methods have same name with same number of arguments. METHOD OVERRIDING is only achieved by Inheritance and Interfaces. EXTRA CONCEPT OF METHOD OVERRIDING: ------------------------------------------------------------------------ Whenever methods parent has by default available to the child through inheritance sometimes child class may not satisfy with the parent method implementation. Then the child class is allow to redefine that method based on its own requirement. This process is called overriding. The parent class method is overridden is called overridden method. The child class method which is overriding is called overriding method.
22nd Apr 2019, 2:55 PM
Rajan Singla
Rajan Singla - avatar
0
Polymorphism is the ability to process the data in more than one form . And function overloading is a way of achieving it
22nd Apr 2019, 12:54 PM
MOIN KHAN
MOIN KHAN - avatar
0
Function overloading is a concept which comes under polymorphism
24th Apr 2019, 2:22 PM
Yogesh Singh
Yogesh Singh - avatar