Last active
June 27, 2022 12:36
-
-
Save alexpanasUCLA/bcda557b07fdbf670d0050d0e86038ba to your computer and use it in GitHub Desktop.
Private modifier lesson
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0; | |
contract check_private { | |
// Declaring private variable | |
uint private _number =2; | |
// Can you check what is private variable | |
// from the contract ? | |
function getter() public view returns(uint) | |
{ | |
return _number; } | |
// Try to modify the value of private variable | |
// inside of the contract | |
function attempt_to_modify() public returns (uint){ | |
return _number += 4; | |
} | |
} | |
contract child is check_private { | |
// By calling this function you can | |
// modify private variable | |
// Not much privacy, isn't? | |
function get_() public returns(uint) | |
{ | |
return attempt_to_modify(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment