Solidity theorytheory 0/50 · 0%
Structure · easy

18. Inheritance and overrides

is, virtual, override and super.

Contracts inherit with `is`. A function meant to be replaced is `virtual`; the replacement is marked `override` and may call `super.f()` to run the parent implementation.

contract Base {
    function fee() public view virtual returns (uint256) { return 1; }
}

contract Child is Base {
    function fee() public view override returns (uint256) { return super.fee() + 1; }
}

With multiple inheritance, the linearisation runs right to left in the `is` list.

Check your understanding

  1. 1. Which keyword marks a function as replaceable?

  2. 2. What does `super.fee()` call?

  3. 3. In `contract C is A, B`, which is most derived?