Overloading
Learn how function overloading works in Solidity.
Multiple functions with the same name but distinct argument types can exist in a contract. This is known as overloading, and it also applies to inherited functions. By allowing developers to utilize familiar function names for comparable processes, this feature simplifies contract to design and improves code readability.
Overloading in inherited functions
Function overloading also applies to inherited functions from parent contracts. In other words, if a contract inherits functions with the same name from many parent contracts, it can overload those functions. This feature ensures that derived contracts can tailor the behavior of inherited functions to their requirements.
External interface overloading
In addition to contract-level overloading, a contract’s external interface can also have overloaded functions. There’s one exception: overloaded functions in the external interface must be of different Solidity types. If two externally visible functions have the same Solidity types but differ solely in external types, a compilation error will occur. External types are those that specify the function’s visibility and access, such as external
, public
, internal
, or private
.
Get hands-on with 1200+ tech skills courses.