Solidify实现一个智能合约3(单继承与多继承)
单继承
方法/函数的继承
代码示例
pragma solidity ^0.4.4;contract Animal {uint _weight;uint private _height;uint internal _age;uint public _money;function test1() constant returns (uint) {return _weight;}function test2() constant public returns (uint) {return _height;}function test3() constant internal returns (uint) {return _age;}function test4() constant private returns (uint) {return _money;}
}//Dog继承Animal,is表示继承
contract Dog is Animal {}
效果如下:
说明:继承中,函数(方法)的权限为public时才能被子合约继承。
属性继承
代码示例
pragma solidity ^0.4.4;contract Animal {uint _weight;uint private _height;uint internal _age;uint public _money;function test1() constant returns (uint) {return _weight;}function test2() constant public returns (uint) {return _height;}function test3() constant internal returns (uint) {return _age;}function test4() constant private returns (uint) {return _money;}
}//Dog继承Animal,is表示继承
contract Dog is Animal {function testWeight() constant returns (uint) {return _weight;}//private属性不能被继承/*function testHeight() constant returns (uint) {return _height; }*/function testAge() constant returns (uint) {return _age;}function testMoney() constant returns (uint) {return _money;}
}
效果如下
说明:子合约可以继承public和internal类型的属性,不能继承private类型的属性。
多继承
代码示例
pragma solidity ^0.4.4;contract Animal {uint _weight;uint private _height;uint internal _age;uint public _money;function test1() constant returns (uint) {return _weight;}function test2() constant public returns (uint) {return _height;}function test3() constant internal returns (uint) {return _age;}function test4() constant private returns (uint) {return _money;}
}contract Sex {uint _sex;function Sex() {_sex = 1;}function sex() constant returns (uint) {return _sex;}
}//Dog继承Animal和Sex,is表示继承,多继承用","分开。
contract Dog is Animal,Sex {function testWeight() constant returns (uint) {return _weight;}//private属性不能被继承/*function testHeight() constant returns (uint) {return _height; }*/function testAge() constant returns (uint) {return _age;}function testMoney() constant returns (uint) {return _money;}
}
效果如下:
说明:效果同上,继承时,子合约的优先级高。
Solidify实现一个智能合约3(单继承与多继承)相关推荐
- Solidify实现一个智能合约2(属性和行为的访问权限)
属性的访问权限 属性:状态变量 属性的权限有三种:public internal private pragma solidity ^0.4.4;/* 属性的权限有三种:public internal ...
- Solidify实现一个智能合约12(字典/映射)
语法 mapping(_keyType => _ValueType) 字典/映射其实就是一个一对一键值对存储关系. 举个例子:{age:18,stuId:10003,name:"His ...
- Solidify实现一个智能合约16(创建一个简单的代币)
创建一个工程,新建一个EncryptedToken合约. 代码如下: pragma solidity ^0.4.4;contract EncryptedToken {uint INITIAL_SUPP ...
- Solidify实现一个智能合约17(创建BLC币)
创建文件夹:mkdir BLC 进入后执行:truffle init 再执行:npm init,一直回车 再执行:npm install zeppelin-solidity hisee@liu:/me ...
- Solidify实现一个智能合约10(一维数组和二维数组)
固定长度的数组 固定长度类型数组的声明及其通过length方法获取数组长度求和. pragma solidity ^0.4.4; /* 数组一旦创建,长度不可变 但里面的内容可变 */ contrac ...
- Solidify实现一个智能合约14(元组)
定义 元组使用小括号,只需要在括号中添加元素,并使用逗号隔开即可. PS:元组中各个元素的类型可以不一样,但数组中的元素必须一样. 示例1 pragma solidity ^0.4.4; contra ...
- Solidify实现一个智能合约5(值类型和引用类型的传递)
值传递 代码示例: pragma solidity ^0.4.4;contract Person {uint _age;function Person(uint age) {_age = age;}f ...
- Solidify实现一个智能合约7(固定大小字节数组)
固定大小字节数组 固定大小字节数组可以通过bytes1,bytes2,bytes3,...,bytes32来进行声明.PS:byte的别名就是bytes1. bytes1只能存储1个字节,也就是二进制 ...
- Solidify实现一个智能合约11(结构体)
结构体的声明 pragma solidity ^0.4.4;contract Students {struct Person {uint age;uint stuId;string name;}Per ...
最新文章
- 全民app使用率排行榜统计全了,微信再次位居榜首!
- access开发精要(15)-货币与数字类型格式(3)
- React开发(135):ant design学习指南之form中动态form新增删除
- 【ZOJ - 4019】Schrödinger's Knapsack (dp,背包,贪心,组内贪心组间dp)
- 为什么你的年薪只是别人的月薪?你需要技术专家帮你「充电」
- 【转】MYSQL入门学习之七:MYSQL常用函数
- java 27 - 7 反射之 通过反射越过泛型检查
- 信息网络传播中的服务器标准,信息网络传播权的服务器标准与实质替代标准之争...
- 设计配色的基本知识以及原理
- 模型微调------学习笔记
- MATLAB读取10bit的raw格式图片代码
- 9.17xiecheng面试总结
- 瑞萨电子RZ/G2L开发板上手评测
- 硬件参数 调整 麦克风MIC灵敏度 原理
- 微信小程序(手机号正则表达式如何验证)手机号格式验证
- 第七阶段 -- 网页编程基础:【HTML】
- 【教学类-29-02】20230402《门牌号-黏贴版打印数量调查教学实践(6层*5间)》-(中班《我爱我家》偏数学)
- 最全MySQL8.0实战教程 14 MySQL的存储过程 14.1 概述
- 探索语言交互技术在政务数字化的应用
- Word操作之参考文献自动关联和引用
热门文章
- Mybatis-plus进阶之分布式id生成
- 移动机器人底盘-四轮差速模型(四轮独立)
- 发送邮件,如何使用java发邮件HuTool发送邮件
- Eureka报错: org.xml.sax.SAXParseException: 前言中不允许有内容。
- android下载图片 服务器,Android网络客户端从服务器电脑上下载图片
- 双光驱+硬盘同步录制会议档案馆录播录像机
- Profinet协议下,MCGS触摸屏能否无线连接PLC?
- UVA 1674 Lightning Energy Report (树链剖分)
- 用一段哲理来鞭策自己
- 服务sql server(MSSQLSERVER)意外停止。这发生了2次。