Polymorphism is an ability to process data in more than one form. Like any other programming language Solidity also supports polymorphism. Solidity supports two types of polymorphism, Function Polymorphism, and Contract Polymorphism.
Function Polymorphism is also known as method overloading. In function polymorphism, multiple functions are declared having the same name within the same contract or inheriting contract. Functions differ on the basis of the number of parameters or parameter datatypes. Declaration of function cannot be overload by functions that differ only in return type.
Example: In the below example, the contract methodOverloading defines two functions with the same name but different argument lists to demonstrate function polymorphism.
Contract polymorphism means using multiple contract instances interchangeably when they are related to each other by using inheritance. This helps in calling the child contract functions using the instance of the parent contract.
Example: In the below example, the contract parent is derived by the child contract child, to demonstrate contract polymorphism. ContractPolymorphism is the driver contract.
- Solidity - Types
- Solidity - Functions
- What are Events in Solidity?
- Solidity - Inheritance
- Solidity - View and Pure Functions
- Solidity - Encapsulation
- Solidity - Abstract Contract
- How to Install Solidity in Windows?
- Solidity - While, Do-While, and For Loop
- Solidity - Break and Continue Statements
- Solidity - Variables
- Solidity - Error Handling
- Steps to Execute Solidity Smart Contract using Remix IDE
- Solidity - Arrays
- Solidity - Enums and Structs
- Solidity - Libraries
- Introduction to Solidity
- Solidity - Constructors
- Solidity - Decision Making Statements
- Solidity - Operators
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.