java编写一个light类,包含两个成员变量,两个构造器方法,三个成员方法
时间: 2024-05-20 13:16:27 浏览: 106
public class Light {
private boolean isOn;
private String color;
public Light() {
this(false, "white");
}
public Light(boolean isOn, String color) {
this.isOn = isOn;
this.color = color;
}
public void turnOn() {
this.isOn = true;
}
public void turnOff() {
this.isOn = false;
}
public void setColor(String color) {
this.color = color;
}
public boolean isOn() {
return isOn;
}
public String getColor() {
return color;
}
}
阅读全文