pragma solidity ^0.4.0;
//连续继承
//son 继承了bb; bb继承了yy,那么son就可以继承yy的属性和函数
contract yeye{
uint public gudong = 2000000;
function zhongdi() public returns(string){
return "zhongdi";
}
}
contract father is yeye{
uint public money = 10000;
function dahan() public returns(string){
return "dahan";
}
}
//son 这个合约继承了father合约
contract son is father{
//继承了father的money属性
function getmoney() public returns(uint){
return money;
}
//继承了father的dahan属性
function jichengbb() public returns(string){
return dahan();
}
function getgudong() public returns(uint){
return gudong;
}
function jichengyy() public returns(string){
return zhongdi();
}
}
32.Solidity-Inherit(继承)
于 2022-11-20 20:00:52 首次发布
本文通过Solidity智能合约语言展示了如何实现多重继承。具体包括一个基础合约yeye定义了公共变量gudong及函数zhongdi,接着father合约继承自yeye并新增属性money和函数dahan,最后son合约继承自father并可以使用来自yeye的所有公开属性和函数。
2704

被折叠的 条评论
为什么被折叠?



