โ Back to Encapsulation
Question 491
Validation Method Returning Bool
Validation Method Returning Bool
TheUserclass has a private fieldage. AddSetAge(int value)that stores the value and returnstrueonly when it is between 0 and 120 inclusive; otherwise it leavesageunchanged and returnsfalse. AddGetAge()that returns the stored age. The tester prints the result ofSetAgeon one line, then the age on the next. Do NOT write aMainmethod. ForSetAge(25)the program prints: True 25 ForSetAge(-5)the program prints: False 0
Expected Output:
True 25
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.