forked from AmazingAng/WTF-Solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_Inheritance.sol
60 lines (48 loc) · 1.34 KB
/
10_Inheritance.sol
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
// 合约继承
contract Yeye {
// 定义3个function: hip(), pop(), man(),返回值设为A。
function hip() public pure virtual returns (string memory){
return("Yeye");
}
function pop() public pure virtual returns (string memory){
return("Yeye");
}
function yeye() public pure virtual returns (string memory){
return("Yeye");
}
}
contract Baba is Yeye{
// 继承两个function: hip()和pop(),返回值改为B。
function hip() public pure virtual override returns (string memory){
return("Baba");
}
function pop() public pure virtual override returns (string memory){
return("Baba");
}
function baba() public pure virtual returns (string memory){
return("Baba");
}
}
contract Erzi is Yeye, Baba{
// 继承两个function: hip()和pop(),返回值改为B。
function hip() public pure virtual override(Yeye, Baba) returns (string memory){
return("Erzi");
}
function pop() public pure virtual override(Yeye, Baba) returns (string memory){
return("Erzi");
}
}
// 构造函数的继承
abstract contract A {
uint public a;
constructor(uint _a) {
a = _a;
}
}
contract B is A(1) {
}
contract C is A {
constructor(uint _c) A(_c * _c) {}
}