-
Notifications
You must be signed in to change notification settings - Fork 121
/
Copy pathAbstract.sol
43 lines (31 loc) · 1.43 KB
/
Abstract.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
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
import "hardhat/console.sol";
/*
Abstract Contract is one which contains at least one function without any implementation.
Such a contract is used as a base contract. Generally an abstract contract contains both implemented as well as abstract functions.
Derived contract will implement the abstract function and use the existing functions as and when required.
In case, a derived contract is not implementing the abstract function then this derived contract will be marked as abstract.
*/
//IN Case we have Parent Contract with functionA which is not implimented in that contract but child contract will implement this function
// so for that we have to mark Parent Contract as abstract and make function virtual of Parent contract
abstract contract ContractA {
function getResult() public pure returns(uint) { return 50; }
function getData() public pure virtual returns(uint) ;
}
contract ContractB is ContractA {
function getData() public pure override returns(uint){
return 12;
}
}
contract ContractC {
uint value;
function checkfunctionA() public returns(uint256) {
//ContractA a = new ContractA();// we can't deploy abstract contract
ContractB b = new ContractB();
value = b.getData();
}
function ResutlCheckfunction() public view returns(uint256) {
return value;
}
}