← Unit 3 · all exercises
Saved in this browser only

A light switch

Write a LightSwitch class that starts off. flip changes it between on and off, and isOn returns whether it is currently on.

class LightSwitch { LightSwitch(); void flip(); boolean isOn(); }

LightSwitch.java
Loading editor…
Results

Examples

  • new LightSwitch().isOn() → false
  • LightSwitch l = new LightSwitch(); l.flip(); l.isOn() → true

There are also 2 hidden tests you can't see. Solve the problem, not the examples.