-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathline20.sol
More file actions
64 lines (47 loc) · 1.43 KB
/
line20.sol
File metadata and controls
64 lines (47 loc) · 1.43 KB
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
// SPDX-License-Identifier: MIT
//SPDX-License-Idetifier: Unlicensed
// Inheritance in Solidity
// Inheritance is a way to create new contracts using existing contracts as building blocks. The new contract will inherit all the state variables and functions from the parent contract. The new contract can also add new state variables and functions.
// The new contract can override some of the functions of the parent contract. This is useful when you want to change the behavior of a function inherited from a parent contract.
// The new contract can also add new functions that are not present in the parent contract.
// import "hash.sol";
pragma solidity >=0.7.0;
contract A {
uint public x = 10;
function getX() virtual public view returns(uint) {
return x;
}
}
contract B is A {
uint public y = 20;
function getY() public view returns(uint) {
return y;
}
}
contract C is A {
uint public z = 30;
function getZ() public view returns(uint) {
return z;
}
function getX() public view override returns(uint) {
return x + 1;
}
}
contract D is B, C {
function getSum() public view returns(uint) {
return x + y + z;
}
}
contract a {
uint public num;
constructor(uint _num){
num = _num;
}
}
contract b is a {
constructor(uint _num) a(_num) {
}
function getNum() public view returns(uint) {
return num;
}
}