Java - Classes and Objects
Consider the following Java code:
class Light {
boolean isOn = false;
void toggle() {
isOn = !isOn;
}
boolean status() {
return isOn;
}
}
class Room {
Light light = new Light();
void switchLight() {
light.toggle();
}
boolean lightStatus() {
return light.status();
}
}
public class Main {
public static void main(String[] args) {
Room room = new Room();
System.out.println(room.lightStatus());
room.switchLight();
System.out.println(room.lightStatus());
}
}What is the output when this program runs?
