A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

【转载】        https://blog.csdn.net/wtdask/article/details/81980649
子合约继承的属性和方法的权限pragma solidity ^0.4.4;/*public >internal(这是合约属性默认的访问权限) >private */contract Animal {  uint _weight;  uint private _height;  uint internal _age;  uint public _money; //public  function test() constant public returns (uint) {    return _weight;  }  function test1() constant public returns (uint) {    return _height;  }  function test2() constant internal returns (uint) {    return _age;  }  function test3() constant private returns (uint) {    return _money;  }}contract Dog is Animal{  function testWeigh() constant public returns (uint) {    return _weight;  }  function testHeight() constant public returns (uint) {    return _height;  }  function testAge() constant public returns (uint) {    return _age;  }  function testMoney() constant public returns (uint) {    return _money;  }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49

子合约只可以继承public类型的函数,而子合约可以继承public和internal类型的属性。

pragma solidity ^0.4.4;/*public >internal(这是合约属性默认的访问权限) >private */contract Animal {  uint _weight;  uint private _height;  uint internal _age;  uint public _money; //public  function test() constant public returns (uint) {    return _weight;  }  function test1() constant public returns (uint) {    return _height;  }  function test2() constant internal returns (uint) {    return _age;  }  function test3() constant private returns (uint) {    return _money;  }}contract Animal1 {  uint _sex;//1 男  0 女  function Animal1() public {    _sex = 1;  }  function sex() constant public returns (uint) {    return _sex;  }}contract Dog is Animal,Animal1{  function testWeigh() constant public returns (uint) {    return _weight;  }  /* function testHeight() constant public returns (uint) {    return _height;  } */  function testAge() constant public returns (uint) {    return _age;  }  function testMoney() constant public returns (uint) {    return _money;  }  function sex() constant returns (uint) {    return 0;  }}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66



2 个回复

倒序浏览
回复 使用道具 举报
奈斯,加油加油
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马