【转载】 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
|