📅  最后修改于: 2020-11-04 04:28:48             🧑  作者: Mango
继承是扩展合同功能的一种方法。 Solidity支持单继承和多继承。以下是关键的高亮点。
pragma solidity ^0.5.0;
contract C {
//private state variable
uint private data;
//public state variable
uint public info;
//constructor
constructor() public {
info = 10;
}
//private function
function increment(uint a) private pure returns(uint) { return a + 1; }
//public function
function updateData(uint a) public { data = a; }
function getData() public view returns(uint) { return data; }
function compute(uint a, uint b) internal pure returns (uint) { return a + b; }
}
//Derived Contract
contract E is C {
uint private result;
C private c;
constructor() public {
c = new C();
}
function getComputedResult() public {
result = compute(3, 5);
}
function getResult() public view returns(uint) { return result; }
function getData() public view returns(uint) { return c.info(); }
}
使用Solidity First Application一章中提供的步骤运行上述程序。运行各种合同方法。对于E.getComputedResult()然后是E.getResult()显示-
0: uint256: 8