I came across the super
keyword in Solidity in the context of overriding functions. What does it do?
Solidity Super Keyword – What Does the Keyword `super` in Solidity Do?
solidity
Related Topic
- Solidity – What is the ‘receive’ Keyword in Solidity?
- Solidity – What is the Immutable Keyword?
- Solidity Syntax – What is the Use of Question Mark ‘?’ in Solidity
- Solidity – How to Use ‘super’ When Overriding Multiple Parents in Solidity Contracts
- Solidity – Can the Storage Keyword be Used in a Solidity Library?
Best Answer
The
super
keyword in Solidity gives access to the immediate parent contract from which the current contract is derived. When having acontract A
with afunction f()
that derives fromB
which also has afunction f()
,A
overrides thef
ofB
. That means thatmyInstanceOfA.f()
will call the version off
that is implemented insideA
itself, the original version implemented insideB
is not visible anymore. The original functionf
fromB
(beingA
's parent) is thus available insideA
viasuper.f()
. Alternatively, one can explicitly specifying the parent of which one wants to call the overridden function because multiple overriding steps are possible as exemplified in the example below: