โ Back to Encapsulation
Question 481
Guarding Against Negatives
Guarding Against Negatives
TheAccountclass has a private fieldbalance. Add aBalanceproperty whosegetreturns the field and whosesetstoresvalueonly when it is 0 or greater; a negativevaluemust be stored as 0. Do NOT write aMainmethod. ForBalance = -50the program prints: 0 ForBalance = 100the program prints: 100
Expected Output:
0
Topics:
Encapsulation
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.