Created
May 29, 2025 15:10
-
-
Save amrahsali/5ce2eb829965d5d0fddc0e5406d1c194 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class BankAccount { | |
int _balance = 1000; | |
int get amount => _balance; | |
set amount(int value) { | |
if (value < 0) { | |
print('error message'); | |
} else { | |
_balance = value; | |
} | |
} | |
} | |
void main() { | |
BankAccount account = BankAccount(); | |
print(account.amount); | |
account.amount = -100; | |
print('new balace: ${account.amount}'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment