-
Notifications
You must be signed in to change notification settings - Fork 2
/
032-advanced-inheritance.sol
48 lines (37 loc) · 1.17 KB
/
032-advanced-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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
/**
* Advanced Inheritance
*
* @title Advances Inheritance
* @notice Inheritance is a way to extend functionality of a contract
* Solidity supports single as well as multiple inheritance
*
* @dev A contract in solidity is similar to a class in C++ --which ia a blueprint for an object
* Classes can inherit other classes, so can contracts inherit other contracts!
*
* REMINDER: A constructor is a special function declared with the constructor keyword which will be
* executed once per contract and is invoked when a contract is created.
*/
// contract C
contract AdvancedInheritance {
}
contract FirstContract {}
// second contract inheriting the first contract
contract secondContract is FirstContract {
}
// Exercise
contract A {
uint256 public innerVal = 100;
function innerAddTen(uint256 value) public pure returns (uint256) {
return value + 10;
}
}
contract B is A {
function runInnerAddTenFromA(uint256 value) public pure returns (uint256) {
return A.innerAddTen(value);
}
function getInnerVal() public view returns (uint256) {
return innerVal;
}
}