forked from AmazingAng/WTF-Solidity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inheritance.sol
70 lines (56 loc) · 1.26 KB
/
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
61
62
63
64
65
66
67
68
69
70
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
// Contrato de herança
contract Yeye {
event Log(string msg);
// Definir 3 funções: hip(), pop() e man(), com o valor de Log como Yeye.
function hip() public virtual{
emit Log("Yeye");
}
function pop() public virtual{
emit Log("Yeye");
}
function yeye() public virtual {
emit Log("Yeye");
}
}
contract Baba is Yeye{
// class Baba extends hip() {
pop() {
co console.log("Baba")
}
}
function pop() public virtual override{
emit Log("Baba");
}
function baba() public virtual{
emit Log("Baba");
}
}
contract Erzi is Yeye, Baba{
// Herda duas funções: hip() e pop(), e altera a saída para "Erzi".
function hip() public virtual override(Yeye, Baba){
emit Log("Erzi");
}
function pop() public virtual override(Yeye, Baba) {
emit Log("Erzi");
}
function callParent() public{
Yeye.pop();
}
function callParentSuper() public{
super.pop();
}
}
// Herança de construtores
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) {}
}