首先看一段官网的描述:
Solidity supports multiple inheritance by copying code including polymorphism.
When a contract inherits from multiple contracts, only a single contract is created on the blockchain, and the code from all the base contracts is copied into the created contract.
The general inheritance system is very similar to Python’s, especially concerning multiple inheritance.
翻译过来是:Solidity支持多继承和多态,实验的方式是通过直接的代码拷贝。当一个合约从多个合约继承的时候,只有一个合约(子类)会被部署到区块链上,而其他的代码会被拷贝到这个单一的合约中去。Solidity的继承方式和Python的极为类似,主要的区别在与Solidity支持多继承,而Python不支持。
重点:Solidity的继承原理是代码拷贝,因此换句话说,继承的写法总是能够写成一个单独的合约。下面举几个例子来说明:(判断两个合约完全相同的原理是编译两个合约,比较它们的bytecode除了swarm hash部分是否相同)
例子一&#