-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructor practice
More file actions
42 lines (33 loc) · 815 Bytes
/
constructor practice
File metadata and controls
42 lines (33 loc) · 815 Bytes
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
pragma solidity ^0.8.0;
contract Member {
string name;
uint age;
// Initialize name and age upon deployment
constructor(string memory _name, uint _age) {
name = _name;
age = _age;
}
}
contract Teacher is Member {
// Inherit from Member and set default values ('Rachel', 28)
constructor(string memory n, uint a) Member(n, a) {}
function getAge() public view returns(uint) {
return age;
}
}
contract Base {
uint data;
constructor(uint _data) {
data = _data;
}
function getData() public view returns(uint) {
return data;
}
}
contract Derived is Base {
// Inherit from Base and set default value (5)
constructor() Base(5) {}
function getBaseData() public pure returns(uint) {
return 5;
}
}