โ Back to Encapsulation
Question 461
Toggle a Private Boolean
Toggle a Private Boolean
Create a classLightSwitchwith aprivate bool isOnthat startsfalse. Add aToggle()method that flips it (false becomes true, true becomes false) and anIsOn()method that returns the current state. Do not write aMainmethod. After oneToggle()the program prints: True
Expected Output:
True
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.