Function polymorphism

Function polymorphism refers to declaring multiple functions within the same contract or inheriting contracts having the same name. The functions differ in the parameter data types or in the number of parameters. Return types are not taken into consideration for determining valid function signatures for polymorphism. This is also known as method overloading.

The next code segment illustrates a contract that contains two functions, which have the same name but different data types for incoming parameters. The first function, getVariableData, accepts int8 as its parameter data type, while the next function having the same name accepts int16 as its parameter data type. It is absolutely legal to have the same function name ...

Get Solidity Programming Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.