Difference between Polymorphism and Overloading

Key Difference: Polymorphism feature allows the user to handle different data types and functions with a uniform interface. A function that can evaluate to or be applied to values of different types is known as a polymorphic function. 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.

Polymorphism and Overloading are two types of functions that are used in OOP (object-oriented programming). 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 feature allows the user to handle different data types and functions with a uniform interface. A function that can evaluate to or be applied to values of different types is known as a polymorphic function. It involves changing the implementation/functionality of a specific method across various types which have the same base-type. In OOP, subtype polymorphism is referred to as simply polymorphism and it has the ability to create a variable (which can be a function or an object) that has more than one form. According to Wikipedia.org, “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 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. In overloading, the user can write multiple methods using the same name, but which have different parameters. 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. Wikipedia.org states, “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.”

Image Courtesy: stackoverflow.com, powerbuilder.hyderabad-colleges.com

Most Searched in Education and References Most Searched in Society and Culture
Most Searched in Sports Most Searched in Home and Garden
AGP vs PCI
Plasma Membrane vs Cell Wall
Sunmica vs Laminate
Revenue vs Receipt

Add new comment

Plain text

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.