Search⌘ K
AI Features

Inheritance, Abstract Contracts, and Interfaces

Explore the concepts of inheritance in Solidity, including how base and derived contracts interact. Understand abstract contracts with virtual functions and the role of interfaces to define contract structures. This lesson helps you implement and override functions to build secure, reusable smart contracts.

We'll cover the following...

Inheritance

In object-oriented programming, inheritance is a program’s ability to use another program’s functionality. In Solidity, it allows us to extend our contracts with code that has been proven to be secure and keep them organized and maintainable. The contract providing this code is known as a base contract, whereas the inheriting contract is known as a derived contract.

We declare that a contract inherits from a source using the is keyword as if to say that the derived contract is an instance of the base ...

Solidity
pragma solidity >=0.4.0 <0.7.0;
contract X {}
contract Y is X {}
contract Z is Y {
// This makes Z derive from X as well
}

Code from multiple base contracts can be inherited by a single derived ...