Polymorphism vs method overloading

There have many definition about polymorphism and overloading. Some people said that overloading is one type of polymorphism. While some people said, they are not the same. Because only one function will be allocate in overloading. While the polymorphism need allocate the memory for each redefined member function. Most of the time new bee programmers are confused about it.

https://www.geekboots.com/story/polymorphism-vs-method-overloading


Polymorphism and Overloading are two types of functions that are used in OOP. These are often confused as synonyms because of their similarity in functioning. However, these two are different functions and are used to yield different results.

Polymorphism

The word itself explains the clear meaning. 'Poly' means multiple, while 'morphism' means the process of gradual change from one form to another. Polymorphism feature allows the user to handle different data types and functions with a uniform interface. Thus, same thing will have different forms. Technically, Polymorphism is way of implementing Single Interface in multiple Implementation. Polymorphism is a general term which refers to both overloading and overriding.

According to Wikipedia, "The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior." Polymorphism is concerned with the application of specific implementations to an interface or a more generic base class.

Method Overloading 

Method Overloading is a feature in programming languages that allows creating several methods that have the same name but differ from each other in terms of type of input and output. Overloading is done in same class where the functions or methods with the same name have different signatures. There are two rules in function overriding: The overloaded function must differ either by the arity or data types and the same function name is used for various instances of function call.

According to Wikipedia, "Method overloading is usually associated with statically-typed programming languages which enforce type checking in function calls. When overloading a method, you are really just making a number of different methods that happen to have the same name. It is resolved at compile time which of these methods are used."

Comments