The Solidity programming language provides the use of inheritance, which means smart contracts can be built using other contract’s code. Here is a simple example of a contract inheriting two other contracts:
//SPDX-License-Identifier: MIT
pragma solidity 0.8.13;
contract a{
uint public age = 30;
}
contract b{
string public name = "Jerry";
}
contract c is a,b{
function getInfo() public view returns(uint, string memory){
return (age,name);
}
}
To inherit another contract in Solidity, when defining the current contract, you simply add the “is” keyword with a comma-separated list of the contracts you wish to inherit.